admin管理员组

文章数量:1410674

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?

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?

Share Improve this question asked Jan 19, 2016 at 11:13 Rishi PrakashRishi Prakash 1,8092 gold badges18 silver badges38 bronze badges 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? – Niet the Dark Absol 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? – Rishi Prakash Commented Jan 19, 2016 at 11:33
  • 1 Not necessarely: The limitation es 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. – rdoubleui Commented Jan 19, 2016 at 11:40
Add a ment  | 

1 Answer 1

Reset to default 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/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);
}

本文标签: Do we have an upper limit for number of keys in a JSON array in javascriptStack Overflow