Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON integers: limit on size

Tags:

json

Is it specified anywhere how big JSON integers can be? I'm guessing that they're limited to normal (32 bit) ints, but I can't find anywhere that that's written down. I need to encode identifiers that are longs in Java, so I presume I need to store those as strings in JSON so as not to risk overflow.

like image 594
Ian Dickinson Avatar asked Nov 21 '12 21:11

Ian Dickinson


People also ask

How large can a JSON number be?

One of the more frequently asked questions about the native JSON data type, is what size can a JSON document be. The short answer is that the maximum size is 1GB. However, JSON often changes how data modeling is done, and deserves a slightly longer response.

Does JSON support 64 bit integers?

> JSON doesn't have 64-bit integers. The JSON "number" type has no limitations on the range. All 64-bit integers, both signed and unsigned, can be encoded as JSON numbers.

Can you have integers in JSON?

JSON does not have distinct types for integers and floating-point values. Therefore, the presence or absence of a decimal point is not enough to distinguish between integers and non-integers. For example, 1 and 1.0 are two ways to represent the same value in JSON.

Does JSON have a character limit?

8388096 UNICODE characters or 16776192 LATIN characters are equivalent to 16776192 bytes, which is the absolute maximum length for the JSON type.


2 Answers

A JSON number is not limited by the spec.

JSON number grammar

Since JSON is an abstract format that is not exclusively targeted at JavaScript, the actual target environment determines the boundaries of what can be interpreted.

It's also worth noting that there are no "JSON Integers", they are a sub-set of the "Number" datatype.

like image 110
Tomalak Avatar answered Sep 22 '22 18:09

Tomalak


RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format

This specification allows implementations to set limits on the range and precision of numbers accepted. Since software that implements IEEE 754-2008 binary64 (double precision) numbers [IEEE754] is generally available and widely used, good interoperability can be achieved by implementations that expect no more precision or range than these provide, in the sense that implementations will approximate JSON numbers within the expected precision. A JSON number such as 1E400 or 3.141592653589793238462643383279 may indicate potential interoperability problems, since it suggests that the software that created it expects receiving software to have greater capabilities for numeric magnitude and precision than is widely available.

like image 20
Nolan Avatar answered Sep 22 '22 18:09

Nolan