4 ms·
JSON has integer types/literals AFAIK, it's just that the Javascript implementation doesn't support them.
by heinrich5991 5y ago
JSON has integer types/literals AFAIK, it's just that the Javascript implementation doesn't support them.
- forrestthewoods 5y agoIt has numeric literals. But all JSON number types are f64. Which is sufficient to represent every 32-bit integer, but it can not represent all 64-bit integers. For code that needs a 64-bit integer, which is quite a lot, you have to encode the integer in a string. Lack of 64-bit integer (either signed or unsigned) is a pretty common and well understood pain point when using JSON as an interchange format.
- RedNifre 5y agoNo, that's just how JavaScript reads them, because JavaScript only has float64. JSON itself allows arbitrary large decimal numbers, including uint64.
- forrestthewoods 5y agoI suppose you're right that the formal JSON specification doesn't actual specify what a number actually is. Only that it's a sequence of digits. TIL. In practice, when you are using JSON as an interchange format between tools and systems it is exceptionally likely that you'll be constrained to 64-bit float as the underlying Number data type. Even if there is no JavaScript anywhere in your data pipeline. I have been burned by this repeatedly. For the record, I have never written a single line of JavaScript in my professional career. In any case, my dream format would separate storage type from encoding type and formalize implementation extensions.