alias pp='python -mjson.tool | pygmentize -l javascript'

Colorized JSON pretty printing

Uses pygmentize and python to create indented and colorized JSON output
Sample Output
curl -s http://www.reddit.com/.json | pp

2
By: wires
2012-10-16 13:55:38

These Might Interest You

  • add this command in your vimrc file and using ,=(suppose your leader character is ',') in the json file you want to format to pretty-json


    0
    nnoremap <leader>= :%s~\({\\|}\\|\[\\|\]\)~\r\1\r~g<cr>:%s~,"~,\r"~g<cr>ggvG=
    gywbd · 2014-11-24 03:21:22 0
  • 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

  • 4
    echo '{"json":"obj"}' | python -mjson.tool
    kev · 2011-11-08 10:44:29 0
  • 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
  • Converts YAML file to JSON. Note that you'll need to install PyYAML. Also some YAML data types (like dates) are not supported by JSON).


    4
    python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < file.yaml > file.json
    tebeka · 2013-04-24 00:28:55 0
  • Based / Inspired by malathion's below command http://www.commandlinefu.com/commands/view/20528/convert-csv-to-json Is written for python3 and is very easy to use csv2json *csv will convert all files ending in csv to json eg csv2json file.csv will output a file to file.json Validity of json tested in python3 and below site https://jsonformatter.curiousconcept.com/


    0
    csv2json() { for file in $@; do python -c "import csv,json,fileinput; print(json.dumps(list(csv.reader(fileinput.input()))))" "$file" 1> "${file%%csv}json"; done; }
    snipertyler · 2017-06-28 04:28:32 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: