g1cm2g
Last Updated: October 11, 2018
·
18.72K
· originell

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

13 Responses
Add your response

1693

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.

over 1 year ago ·
2491

{"comment": "Pretty Helpful"}

over 1 year ago ·
2492
over 1 year ago ·
2496

Here's a NodeJS version:

echo '{"foo":"bar"}' | json

You need to install the jsontool module (npm install -g jsontool)

over 1 year ago ·
2500

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 :)

Pretty print JSON from command line with NodeJS

over 1 year ago ·
2548

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

over 1 year ago ·
2553

@dpashkevich Hey! Great job :) Pretty short for not using any third party module!

@manveru ah that's a nice one too :)

over 1 year ago ·
2554

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

over 1 year ago ·
8687

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

over 1 year ago ·
17543

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

over 1 year ago ·
18202

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/

over 1 year ago ·
21180

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

over 1 year ago ·
21673

+1 for jq:

$ echo '{"test1": 1, "test2": "win"}' | jq .

The output is even colored.

over 1 year ago ·
Filed Under