Using json.tool from the shell to validate and pretty-print

echo '{"json":"obj"}' | python -mjson.tool

4
By: kev
2011-11-08 10:44:29

These Might Interest You

  • You can use a site like http://www.jsonlint.com/ or use the command line to validate your long and complex json data. This is part of the simplejson package for python http://undefined.org/python/#simplejson. Wrong json expression example: echo '{ 1.2:3.4}' | python -m simplejson.tool Expecting property name: line 1 column 2 (char 2) Show Sample Output


    12
    echo '{"json":"obj"}' | python -m simplejson.tool
    azeey · 2009-05-10 13:58:05 4
  • Validates and pretty-prints the content fetched from the URL. Show Sample Output


    11
    curl -s "http://feeds.delicious.com/v2/json?count=5" | python -m json.tool | less -R
    keimlink · 2010-03-24 09:15:12 1
  • I have this saved as jsonlint chmodded +x and file.js is instead $1, but YMMV Show Sample Output


    4
    curl -s -X POST http://www.jsonlint.com/ajax/validate -d json="`cat file.js`" -d reformat=no
    reklis · 2010-03-16 20:39:43 3
  • Uses pygmentize and python to create indented and colorized JSON output Show Sample Output


    2
    alias pp='python -mjson.tool | pygmentize -l javascript'
    wires · 2012-10-16 13:55:38 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: