Paul Hammond, 16 April 2013

Most JSON APIs return data in a format optimized for speed over human readability. This is good, except when things are broken.

But that’s OK, because we have Unix Pipes and we can pipe the JSON into a prettifier. But all of the prettifiers start with a JSON parser so they don’t work if the data is invalid. Most of them also make small changes to the data as it passes through – strings get normalized, numbers get reformatted, and so on – which means you can’t be totally sure if your output is accurate. And they’re usually slow.

Last night I wrote a tool called jp which doesn’t have these problems. It works by doing a single pass through the JSON data adding or removing whitespace as needed.

It’s fast. Insanely fast. Reformatting a 161M file on my laptop takes 13 seconds, compared to 44 seconds for JSONPP, or several minutes for the Ruby or Python alternatives. And it’s accurate; it doesn’t change any of the data, just the spaces around it.

You should use it.