Does JavaScript's JSON.Parse() function have a max string length limit for the parameter it accepts? - Stack Overflow

Does JavaScript's JSON.Parse() have a max string length limit for the parameter it accepts? If I p

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
Add a ment  | 

2 Answers 2

Reset to default 4

There'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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信