g1cm2g
Last Updated: July 22, 2017
·
13.17K
· originell
B7aaf37de0dd4c9384d15a61995f6b27

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
Say Thanks
Respond

13 Responses
Add your response

1693
C694a032be7518a0d704318895f8fe1d

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
01d738166e57a8e9e96b605ad02e1b16

{"comment": "Pretty Helpful"}

over 1 year ago ·
2492
Yo
over 1 year ago ·
2496
D42a7264714dee5006b9c99d2567a320

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
D42a7264714dee5006b9c99d2567a320

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
86e33dee4a89a8879a26487051c216a8

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

over 1 year ago ·
2553
B7aaf37de0dd4c9384d15a61995f6b27

@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
543aba69f8cc74c8b0a9c78417e19ecd

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

over 1 year ago ·
8687
58c08dd024c9fe28f009f32378128a57

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
339c8eea1c6d6f770cfac7c888d87eb6 normal

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

over 1 year ago ·
18202
6b7d8c8a5ceba3ce9d67a63b01bf3ccd normal

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
None

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

over 1 year ago ·
21673
70d9b050bfe39350c234d710fadfcd39

+1 for jq:

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

The output is even colored.

over 1 year ago ·
Filed Under