json-stringify-safe icon indicating copy to clipboard operation
json-stringify-safe copied to clipboard

Very deep objects take a long time to stringify, maybe add a `depth` option ?

Open netei opened this issue 9 years ago • 0 comments

I've been trying to log some objects that are very deep, but I'm actually not interested in the full object, just the parts that are not at a too big depth.

I know the current implementation relies on JSON.stringify, which has no depth option, so I'm not sure if it is possible to implement it from here.

Anyway, here's a code sample to reproduce :

  var rootFoo = [];
  var foo = rootFoo;
  for (var j = 0; j < 1000; j++) {
    foo[j] = [];
    for (var i = 0; i < 100; i++) {
      foo[j][i] = foo;
    }
    foo = foo[j]
  }

  process.stdout.write(require("json-stringify-safe")(rootFoo) + "\n");

netei avatar Feb 25 '16 09:02 netei