3 ms·
Every time I go to use JSON it is great until I remember it cannot represent 64 bit integers.
by carom 4y ago
Every time I go to use JSON it is great until I remember it cannot represent 64 bit integers.
- jayd16 4y agoHuh? The json number spec does not specify a precision or size. Any limitation is from your parser.
- gabetax 4y agoThis is a Javascript issue, not a JSON issue. The JSON spec doesn't apply any limits on the number type. ECMA-404 states: > JSON is agnostic about the semantics of numbers. In any programming language, there can be a variety of number types of various capacities and complements, fixed or floating, binary or decimal. That can make interchange between different programming languages difficult. JSON instead offers only the representation of numbers that humans use: a sequence of digits. All programming languages know how to make sense of digit sequences even if they disagree on internal representations. That is enough to allow interchange. It also explicitly excludes NaN encoding, which further distances itself from any coupling to IEEE floating point expectations.
- jillesvangurp 4y agoYep, if you use e.g. Java's jackson, you can configure it easily to deserialize numbers as BigInteger or BigDecimal instances. Useful trick if you need it and it really works. You can have arbitrary precision numbers in Json. Of course this does challenge most other parsers out there.
- vbezhenar 4y agoUse https://www.npmjs.com/package/json-bigint https://www.npmjs.com/package/json-bigint I think that one day browser will support it natively.
- RedShift1 4y agoIn Javascript, when do you need to represent something larger than 2^53 anyway?
- skunkiferous 4y agoSame. We use 64-bit ints as "Entity IDs", and countless other stuff. Saying that it's a "parser problem" is not really helpful, bc many parsers refuse to support 64-bit ints, even if they could, bc compatibility with JavaScript is more important than 64-bit ints for them. For example: jsonnet