6

I am going to create a 1-D JSON array, I just want to be sure about it's scalability. Is there any upper limit on number of key:Value pairs that could be present in a JSON?

3
  • 6
    new Array(1<<31-1) yields Array[1073741824], new Array(1<<31) throws Uncaught RangeError: Invalid array length so... I guess that's your answer? Commented Jan 19, 2016 at 11:16
  • So as intrinsically JSON is also an array, whatever be the upper limit of Array will also be of JSON? Commented Jan 19, 2016 at 11:33
  • 1
    Not necessarely: The limitation comes from the array implementation in JavaScript (and the index used being an integer). So I guess it's up to the language/platform that you're using. But taken that JSON is being used as data exchange format you need to make sure that all sides can handle this amount of data within its own platform/language restrictions. Commented Jan 19, 2016 at 11:40

1 Answer 1

8

JSON is just a textual representation of JS objects so the only limit is the memory storage capacity that holds it.

For actual Javascript Arrays it depends on the implementation by the software, but per the spec:

http://www.ecma-international.org/ecma-262/5.1/#sec-15.4

Every Array object has a length property whose value is always a nonnegative integer less than 2^32

So the limit is (2^32)-1 or 4294967295 if adhering to the spec.

try {
   new Array(4294967295);
} catch(e){
   alert("Should be fine and not see this");
}

try {
  new Array(4294967296);
} catch(e){
  alert(e.name);
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.