How do I pretty print JSON in JavaScript?

To print JSON nicely in JavaScript, you can use the JSON.stringify(obj, replacer, space) method. The third parameter of the JSON.stringify() method specifies the number of spaces to use when outputting the JSON string. In this JavaScript Print JSON example, we use the JSON.stringify() method and specify the number of spaces in the third parameter to print the object in a human-readable format. Click Execute to run the JavaScript Pretty Print JSON Example online and see the result.
Loading...