EN
JavaScript - RangeError: Invalid string length
1
answers
3
points
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
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