Home > database >  JSON numeric limits
JSON numeric limits

Time:09-22

Does JSON have any numeric limits or is it basically "anything goes" with respect to numbers and it's just up to the receiving party to validate and do error checking on the numeric values. For example:

[12e 10000, 9223372036854775808]

enter image description here

The above would be an out-of-bounds value in a language that only supported float64 and int64, so how is this usually done? Or does JSON only specify the grammar (for example for an int 0|[1-9]\d and its up to the processor to determine what to do with it?

CodePudding user response:

The JSON standard does not set any limits on the magnitude or precision of a number; it is only concerned with the syntax. The RFC version is explicit about the fact that the standard permits an implementation to set numeric limits; it does not impose minimum limits.

An implementation which sets a small limit on number magnitude or precision will create interoperability issues; an implementation which outputs numbers outside the possibilities of IEEE754 binary64 may also cause interop issues. Many processors allow numbers to be transmitted as strings, leaving it to the receiver to interpret the string as a number (perhaps with the aid of a schema); this is the only way to transmit infinities and NaN values.

  • Related