Last Updated: February 25, 2016
·
1.554K
· ultimatedelman

Pretty-Print JSON Using JSON.stringify()

Did you know that JSON.stringify() takes additional parameters?

JSON.stringify(myObj, null, 4);

This will pretty-print your stringified JSON object using 4 spaces for indentation. The second parameter is a "replacer" param that determines what is kept or removed from the final string.

Demo

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside