JSON formatter bookmarklet

At work I need to read JSON document pretty often and making it pretty will help me pretty much. Last time I showed how to prettify a JSON document using Python script. But since I am working mostly in a browser, having to switch from browser to terminal is a bit cumbersome. There are a lot of online JSON formatter out there but I think it’s too much if I need to make a remote request just to do the formatting. Also the JSON document I need to format can be a sensitive document so it’s also not a good idea to use an online service.

Then I realized browser nowadays has in-browser JSON formatter function: JSON.stringify. I just need to find a way to make using it a bit easier. So I made the following bookmarklet.

Prettify JSON

Drag the link above to bookmark bar in your browser. If you need to format a JSON document, you can click it, then paste the JSON document (make sure it’s valid), and finally click the button there. Voila!

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!