3 ms·
From RFC 7159 section 6. Numbers: https://tools.ietf.org/html/rfc7159#section-6 https://tools.ietf.org/html/rfc7159#section-6 Note that when such software
by bascule 10y ago
From RFC 7159 section 6. Numbers:
https://tools.ietf.org/html/rfc7159#section-6 https://tools.ietf.org/html/rfc7159#section-6
Note that when such software is used, numbers that are integers and
are in the range [-(2**53)+1, (2**53)-1] are interoperable in the
sense that implementations will agree exactly on their numeric
values.
You can't depend on interoperable support for 64-bit integers in JSON. Furthermore many JSON libraries convert all numbers to floats, so this problem doesn't affect only JavaScript.
TJSON requires conforming parsers to support the full 64-bit signed and unsigned ranges. This will involve using bignums in JavaScript.
- rpedela 10y agoWhich ones besides Javascript implementations? Do you have examples?
- bascule 10y agoGo's JSON parser parses all numbers as floats, for example
- bascule 10y agoAlso note that the sinister problem here is that implementations which convert numbers to floats will silently lose precision when they overflow the range allowed in RFC 7159. This leads to quite subtle errors, and is why Twitter moved to encoding Snowflake IDs as strings: https://blog.twitter.com/2011/important-direct-message-ids-will-become-64-bit-snowflake-ids-on-sep-30 https://blog.twitter.com/2011/important-direct-message-ids-w...