Do you know of any "JSON Beautifier" for JavaScript?
From
{"name":"Steve","surname":"Jobs","company":"Apple"}
To
{
"name" : "Steve",
"surname" : "Jobs",
"company" : "Apple"
}
Example
some_magic(jsonObj); // return beautified JSON
Do you know of any "JSON Beautifier" for JavaScript?
From
{"name":"Steve","surname":"Jobs","company":"Apple"}
To
{
"name" : "Steve",
"surname" : "Jobs",
"company" : "Apple"
}
Example
some_magic(jsonObj); // return beautified JSON
The JSON.stringify
method supported by many modern browsers (including IE8) can output a beautified JSON string:
JSON.stringify(jsObj, null, "\t"); // stringify with tabs inserted at each level
JSON.stringify(jsObj, null, 4); // stringify with 4 spaces at each level
Demo: http://jsfiddle.net/AndyE/HZPVL/
This method is also included with json2.js, for supporting older browsers.
If you don't need to do it programmatically, Try JSON Lint. Not only will it prettify your JSON, it will validate it at the same time.
white-space:pre
in the css is needed as well) –
Shadrach null, 2
, but didn't know that '\t' would work too. Fantastic! –
Moleskin JSON.stringify
does fairly horrible job on lists with lots of numbers, the npm package beautify-json (npm.io/package/beautify-json) does that better. –
Diatropism © 2022 - 2024 — McMap. All rights reserved.