Skip to content

Instantly share code, notes, and snippets.

@ilovejs
Created August 21, 2014 05:38
Show Gist options
  • Save ilovejs/ac969f368c7963f087c6 to your computer and use it in GitHub Desktop.
Save ilovejs/ac969f368c7963f087c6 to your computer and use it in GitHub Desktop.
#!/bin/bash
pretty print JSON from the command line
by RUSLAN SPIVAK on OCTOBER 12, 2010
Recently I’ve worked on a small project where I needed to pretty print JSON from the command line for quick verification.
For the task I created a pp alias in my .bashrc that worked perfectly (all the code is on the same line):
alias pp='python -c "import sys, json; print json.dumps(
json.load(sys.stdin), sort_keys=True, indent=4)"'
Just today I was re-reading the official Python documentation on a json package and came across a small gem – json.tool module that is used for validation and pretty-printing.
I modified my alias which is now way shorter and does the same job as my old one:
alias pp='python -mjson.tool'
And here is pretty-printing in action:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment