9 ms·
That is not true of JSON numbers either practically or technically. This specification allows implementations to set limits on the range and precision of num
by mgraczyk 7y ago
That is not true of JSON numbers either practically or technically.
This specification allows implementations to set limits on the range and precision of numbers accepted.
https://tools.ietf.org/html/rfc7159#section-6 https://tools.ietf.org/html/rfc7159#section-6
- SahAssar 7y agoYes it is. All that part of the spec says is that it allows implementations to set/have limits on ranges and precision, which is obvious because for example javascript only has 53 bit numbers. Other implementations can have other limits, but that does not mean that JSON itself or all implementations have the specific limits of javascript.
- megous 7y agoNot anymore. Try writing 10000000000000000000000000000000000000000000000000000000000000000000000000000000n + 1n into your browser console.
- majewsky 7y agoWell yeah, those are bigints, but JSON does not support bigints, so the point still stands.
- nemetroid 7y agoIf by "JSON" you mean "JSON parsers in web browsers", then yes.
- howdydoo 7y agoFirefox: >JSON.stringify(1n) TypeError: BigInt value can't be serialized in JSON Chrome: >JSON.stringify(1n) Uncaught TypeError: Do not know how to serialize a BigInt at JSON.stringify (<anonymous>) at <anonymous>:1:6 I don't think we're quite there yet.
- megous 7y agoIt was counterpoint to "that does not mean that JSON itself or all implementations have the specific limits of javascript." Javascript can do arbitrary precision integers now. So the last part is not true. You can generate your JSON strings with string concatenation in JS if you like. Just because JSON.stringify has some limit doesn't mean JS has.
- apaprocki 7y agoSee my comment elsewhere in the thread that shows how to properly use BigInts with JSON.stringify, if you choose to support them in your environment.
- raverbashing 7y agoI'm assuming the percentage of problems where the difference between 64 bits and 53 bits precision matter are really, really small (and you should be paying attention then, because you're bound to lose precision in other parts and not only in JSON) For everything else, it is really a non-issue.
- mgraczyk 7y agoIt is not the case that JSON numbers are "arbitrary precision". JSON numbers are in fact "implementation defined" precision. The technical and practical implication is exactly what was described in the article: Since precision is implementation defined (not uniform and with no lower-bound), JSON numbers make a poor vessel for inter-service communication.