Hi,
do you know any "JSON Beautifier"? Thanks!
From
{"name":"Steve","surname":"Jobs","company":"Apple"}
To
{
"name" : "Steve",
"surname" : "Jobs",
"company" : "Apple"
}
Example
some_magic(jsonObj); // return beauty json file
Hi,
do you know any "JSON Beautifier"? Thanks!
From
{"name":"Steve","surname":"Jobs","company":"Apple"}
To
{
"name" : "Steve",
"surname" : "Jobs",
"company" : "Apple"
}
Example
some_magic(jsonObj); // return beauty json file
Just paste it into: http://www.jsonlint.com/
Validation and beautification :)
If you just want beautification, this works on JSON as well as any javascript code: http://jsbeautifier.org/
Try JSON Lint. Not only will it prettify your JSON, it will validate it at the same time :-)
undeleted after your edit
If you want to do this programmatically, 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
This method is also included with json2.js. IE8/Chrome/Safari example at http://jsbin.com/asoya3/edit
Here's something that might be interesting for developers hacking (minified or obfuscated) JavaScript more frequently.
You can build your own CLI JavaScript beautifier in under 5 mins and have it handy on the command-line. You'll need Mozilla Rhino, JavaScript file of some of the JS beautifiers available online, small hack and a script file to wrap it all up.
I wrote an article explaining the procedure: Command-line JavaScript beautifier implemented in JavaScript.
Cheers!
Shonzilla