Languages

JavaScript - RangeError: Invalid string length

3 points
Asked by:
Creg
9600

Any idea why my JavaScript source code throws exception when I try to ocnvert object to JSON using JSON.stringify() method?

Error:

rest.tsx:194 RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at Object.<anonymous> (rest.tsx:167:34)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (record.tsx:78:2)
    at _next (record.tsx:78:2)
    at record.tsx:78:2
    at new Promise (<anonymous>)
    at Object.<anonymous> (record.tsx:78:2)
    at Object.sendData (rest.tsx:163:22)
    at Object.<anonymous> (useRequest.tsx:57:50)
1 answer
5 points
Answered by:
Creg
9600

The RangeError: Invalid string length in JavaScript often occurs when you're trying to stringify a very large or circular object with JSON.stringify() method. This can happen if the object you're passing to JSON.stringify() method is too large to be handled or contains references that cause infinite loops.

The solution is to call JSON.stringify() method on smaller peaces of object and join them to final JSON using + operation on strings.

0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join