I’ve been a pretty big fan of jq for a number of things:
* lots of my logs these days are in json (so they’re machine parseable and human readable). It makes filtering them child’s play.
* Some of our ETL pipelines have a decent amount of JSON in them and jq makes it pretty quick / short work to do pre / post processing pretty quickly.
However, if all your need is quick access to pretty-printing, consider piping to ‘python -m json.tool’, which will already be available on most systems.
python -m json.tool really is an invaluable tool to have, both for pretty printing and verifying that the JSON itself is valid. I love sharing it with teammates and seeing their joyous reactions.
python -m json.tool
I am always finding myself looking at a blob of json in vim (pasted or otherwise), and a quick reformat is only a few keys away:
:%!python -m json.tool
Works for jq too:
The only problem I’ve had with jq is that things like tonumber don’t compose correctly in random ways. So I usually just add a quick sed command after anything I don’t understand with jq :P
I’d love to see jq implemented more efficiently, and with some of it’s syntatical warts removed, or maybe a different syntax that makes it more obvious the chain of operations, and what parts of an array / object you’re working on. For me that would be something more like list comprehensions.
I’ve used Jolt for the same genre of thing: https://github.com/bazaarvoice/jolt
Might be a bit more heavyweight: I probably wouldn’t use it for one-off command lines. But it’s worth looking into.