Re:Data serialization
by dchest on Monday June 04, 2018 @09:09AM
(#17227334)
Arbitrary precision integers is a JavaScript implementation detail; JSON standard doesn't specify number precision.
[ Parent
| on HN ]
In theory, that is true. In practice, if the consuming client is javascript, it is really hard to map the numbers into an arbitrary precision number upon decoding (which would come from some library like big.js), rather than a pure double.
Which means, in practice, you are stuck passing numbers as strings (and on the javascript side, pass that string into the arbitrary precision number library)
Huh good to know:
$ node
> JSON.parse('1231231231231231231231231123123123123')
1.2312312312312312e+36
I've heard of JSON implementations in other languages making bigger JSON numbers than javascript supports; but I didn't realise JSON.parse would quietly parse them and throw away precision in the process. I wonder what the plan is for JSON serialization support of bigints. I assume there is no plan - Chrome stable 67 supports bigints, but JSON.serialize(2n) throws a TypeError.