javascript

Prettify JSON object or array using JSON.stringify

If you want to prettify JSON data with fixed spaces in the output, you can use JSON.stringify() method

const json_data = {id: 10001, name: "Tokyo", show: "La Casa De papel"};
const pretty_json_str = JSON.stringify(json_data, undefined, 4);
Output
{
"id": 10001,
"name": "Tokyo",
"show": "La Casa De papel"
}

LIVE DEMO

Was this helpful?