Commandline JSON Pretty Print everywhere
You can pretty print (and validate) json on nearly every *nix-like (unix, linux, osx,…) system, since most of them have Python (2.6+ required) installed.
echo '{"test1": 1, "test2": "win"}' | python -m json.tool
will be returned as:
{
"test1": 1,
"test2": "win"
}
And yep, you guessed it, this can easily be integrated with your favorite editor of choice, as long as it supports passing data to a shell command.
Pretty printing a JSON file with VIM and Python:
:%!python -m json.tool
Related protips:
Written by Luis Nell
Related protips
12 Responses

If the machine has pygments installed (not as likely, but easy to install) you can pipe the json for color output as well python -mjson.tool | pygmentize -l javascript
.

{"comment": "Pretty Helpful"}

Here's a NodeJS version:
echo '{"foo":"bar"}' | json
You need to install the jsontool
module (npm install -g jsontool
)

You insipred me to attempt to repeat this in NodeJS without 3rd party modules. Turned out it's shorter in Python due to json.tool
moduel existence :)

Ruby version: ruby -rjson -e 'puts JSON.pretty_generate(JSON.load($<))'

@dpashkevich Hey! Great job :) Pretty short for not using any third party module!
@manveru ah that's a nice one too :)

I usually use this little wrapper: https://github.com/igorgue/pjson which adds pretty colors.

I wish I could get the pretty color version when viewing JSON files in ST2. You'd think it was possible seeing as ST2 is heavily connected to Python

I use this neat little tool: www.jsonprettyprint.net. Does the job for me.

Very helpful, specifically the VIM shortcut. I've reblogged this post along with additional JSON pretty printing tools at http://techzog.com/development/json-and-xml-in-human-readable-form/

I like Stephen Dolan's jq for working with JSON on the CLI: http://stedolan.github.io/jq
