in json javascript prettyprint ~ read.

Pretty printing of JSON in javascript

I like JSON very much. It's easy to read, easy to work with, but when you get a big structure, it's handy to have some quick way for print it out in a nice readable format. Before i was using Sublime Text editor with PrettyJson plugin. But now i started to learn Javascript and it's i started to look for a nice library that would allow me to print out JSON on a webpage in a nice structured way. I was pleasantly surprised to find out that standard JSON library supports it out of the box !

To use it you just can write :

var jsonFormattedString = JSON.stringify(json, null, 2); // spacing level = 2

And that's it ! You will get a nicely formatted json.

In case you would like also to add some colors to your formatted json, you can use this snippet :

comments powered by Disqus
comments powered by Disqus