最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论