pretty-print JSON using JavaScript

Created by user123444555621Linked to 40.7m issues across 190 teams


Pretty-printing JSON using JavaScript involves using the JSON.stringify() method. This method takes a JavaScript object as an argument and returns a string representation of the object.

For example, if we have the following JavaScript object:

const myObject = { name: 'John', age: 30 };

We can pretty-print it using the JSON.stringify() method like so:

console.log(JSON.stringify(myObject, null, 4));

This will output the following string:

{ "name": "John", "age": 30 }