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

Web Developer, Business Analytics, Data Engineer specialising in PHP and Tableau

Based in Melbourne, Australia

Feel free to contact me or _justin_kelly

Leave a comment

Notify me of replies by email.