Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we have an upper limit for number of keys in a JSON array in javascript?

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?

like image 701
Rishi Avatar asked Jan 19 '16 11:01

Rishi


1 Answers

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);
}
like image 115
Patrick Evans Avatar answered Oct 25 '22 18:10

Patrick Evans