DEV Community


Posted on • Updated on

Simplest solution to JSON.stringify RangeError: Invalid string length

We often come across this issue where the object or value passed to JSON.stringify is more than it can handle and the most common solution offered on google is using alternate libraries to stream the data whereas the simplest solution to it is just to stringify one element at a time and concatenate them.

var out="[";
  for(var indx=0;indx<data.length-1;indx++){
Enter fullscreen mode Exit fullscreen mode

You can also save the gist here for future references.
Hope this solution helps you at some point.

Top comments (0)