Working with an object that seems to be too nested and that I want to hard-clone, I get a
var copy = JSON.parse(JSON.stringify(big_object));
-> RangeError: Invalid string length for a too large string
I have workarounded it by cloning it while skipping the first nested layer
var copy = {};
for (o in big_object) {
copy[o] = JSON.parse(JSON.stringify(big_object[o]));
}
But I am wondering what is this limit? In my case I get this error by doing the following:
var objs = {};
var objs.obj1 = JSON.parse(obj1);
var objs.obj2 = JSON.parse(obj2);
var objs.obj3 = JSON.parse(obj3);
var objs.obj4 = JSON.parse(obj4);
var objs.obj5 = JSON.parse(obj5);
....
var objs.obj6 = JSON.parse(objn);
....
var copy = JSON.parse(JSON.stringify(objs));
where obj1..n are JSON files of ~40 Mb each that the user decides to process. When I process 7 files, no problem. When I process 8 files, I get the error.
*The size is 1.9Gb, this hardly seems to be my case (see Is there a limit on the size of a string in JSON with Node.js?)