How to pretty-print JSON in linux

If you are working with an JSON API from the Linux commandline with tools like curl, you will often find that the JSON is returned in just one big long line.

To make this readable you can use the python json module and pipe the output to less.

alias prettyjson='python -m json.tool | less'

To make this alias permanent, put the above line in your .bashrc file

echo "alias prettyjson='python -m json.tool | less'" >> ~/.bashrc

To use this alias, pipe the curl output to prettyjson like below

curl http://someurl/api | prettyjson

Justin Kelly

Justin Kelly

Data Engineeer, Business Analytics, Web Developer, Library Technology specialising in PHP and Tableau

Based in Melbourne, Australia

Feel free to contact me justin@kelly.org.au or _justin_kelly