Easy JSON Formatting for Browsers
If you're writing a web page that needs to display JSON, you probably want to display it nicely with proper indentation.
There's no need to look for a javascript library, the browser can do it for you!
JSON.stringify({hi:"there",arr:[1,2,2],reality:true,child:{}}, null, 2)
Will give you a string with this:
{
"hi": "there",
"arr": [
1,
2,
2
],
"reality": true,
"child": {}
}
The trick is the 3rd parameter to JSON.stringify(). It tells the browser's JSON encoder to indent by that many spaces.
Written by Jon Abrams
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#