Monday, 22 May 2017

JSON stringify util.inspect

I want to use util.inspect (because I want to limit the depth of JSON.stringify.

But the result is not a JSON.stringify object:

const obj = {foo: 'bar'};
console.log(JSON.parse(util.inspect(obj)));

SyntaxError: Unexpected token f in JSON at position 2

How do I parse the response of util.inspect?



via Kousha

No comments:

Post a Comment