9 ms·
JSON doesn't use Javascript doubles. It uses a custom format that excludes NaNs and Infinities. It allows arbitrary precision values: "A number is a sequence of
by SAI_Peregrinus 6y ago
JSON doesn't use Javascript doubles. It uses a custom format that excludes NaNs and Infinities. It allows arbitrary precision values: "A number is a sequence of decimal digits with no superfluous leading zero. It may have a preceding minus sign (U+002D). It may have a fractional part prefixed by a decimal point (U+002E). It may have an exponent, prefixed by e (U+0065) or E (U+0045) and optionally + (U+002B) or – (U+002D). The digits are the code points U+0030 through U+0039. Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted."—ECMA-404[1]
That means that not all JSON values can be represented as IEEE754 doubles (Javascript Numbers) and not all IEEE754 doubles can be represented as JSON values. It's a lossy conversion.
[1] https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf https://www.ecma-international.org/publications/files/ECMA-S...