Does JavaScript's JSON.Parse()
have a max string length limit for the parameter it accepts? If I pass a string to JSON.Parse()
that exceeds the specific length, will it through an exception or decline from returning a valid value?
Please provide an answer supported from valid resources. Thanks in advance.
Does JavaScript's JSON.Parse()
have a max string length limit for the parameter it accepts? If I pass a string to JSON.Parse()
that exceeds the specific length, will it through an exception or decline from returning a valid value?
Please provide an answer supported from valid resources. Thanks in advance.
Share edited Dec 23, 2019 at 15:47 Adam 2,5801 gold badge25 silver badges35 bronze badges asked Dec 23, 2019 at 15:22 YazanYazan 711 silver badge8 bronze badges 1-
And what is with all these tags? Why
asp
,parameters
,asp-mvc-5
? – Andreas Commented Dec 23, 2019 at 15:25
2 Answers
Reset to default 4There's no inherant size limits on JSON, but there can be limitations set by the browser or the server sending / handling related requests. For example, ASP has JavaScriptSerializer.MaxJsonLength
which can limit the length (defaults to 2097152)
This takes an 32-bit interger, and so is limited to 2147483644 characters
Int32
The maximum length of JSON strings. The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data.
With Node.js & V8, the limit to JSON.parse() is the runtime's max string length, which is currently around 2^29 characters (~512MB) on 64-bit platforms [1].
function jsonParseMaxStringSize(size) {
try {
// subtract 2 for the quotes
JSON.parse(`"${"a".repeat(size - 2)}"`);
console.log("cool");
} catch {
console.log("no dice");
}
}
jsonParseMaxStringSize(2 ** 29 - 24); // cool
jsonParseMaxStringSize(2 ** 29 - 23); // no dice
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744933412a4601873.html
评论列表(0条)