How to pretty-print JSON in linux
21 Jul 2017If 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