JSON prettifier

Once in a while I need to prettify a JSON document (read: add indentations and new lines) to make it (more) readable. Usually what I will do is finding an online prettifier and copy-paste the JSON onto there. What I usually don’t realize is that I already have that tool in my toolbox! I figured this out from a post somewhere on the net, sorry I don’t remember exactly where.

If you have Python installed, that means you already have a tool that can make a JSON document pretty. Just use it as the following.

$ python -m json.tool document.json

Or if you are an stdin fan, it can also read from there.

$ python -m json.tool < document.json

There you have it!

Leave a Reply