3000 explained code solutions for 75 technologies


nodejsHow to pretty print JSON stringify


const json = {name: 'Joe', age: 98};
const pretty = JSON.stringify(json, null, 2)ctrl + c
{name: 'Joe', age: 98}

sample JSON to encode and pretty print

JSON.stringify(

convert given object to JSON string

2

indent size to use for JSON formatting (2 spaces in our case)