feuocg
Last Updated: February 25, 2016
·
9.505K
· douglas-c-thomas
Avatar

JSON.stringify() pretty printer

I normally format my JSON when debugging in python with:

logger.debug('my stuff: %s' % json.dumps(my_json, indent=4)) 

But I found out you can do the same in Javascript by adding a couple of extra parameters to the JSON.stringify() function, like:

console.log('my stuff: ' + JSON.stringify(my_json, undefined, 4));

More at: https://developer.mozilla.org/en-US/docs/Using_native_JSON

Say Thanks
Respond

1 Response
Add your response

2329
D42a7264714dee5006b9c99d2567a320

I discovered that recently too, pretty neat!
What I think would be cool is another parameter that specifies the initial indent of pretty-printed json block. Would be useful if I want to output the result of JSON.stringify inside an already existing piece of code... Anybody knows of an easy way to do this?

over 1 year ago ·