From charlesreid1

from command line

to prettify json in a one-liner, just pipe it to python's json.tool:

echo '{"foo": "lorem", "bar": "ipsum"}' | python -m json.tool


from a python script

to print out pretty json using Python:

d = dict(a=1,b=2,c=3)
with open('pretty.json','w') as f:
    json.dump(d, f, separators=(',',': '),indent=4)