If you haven’t tried it out yet, I highly recommend checking out the application jq. It allows you to quickly format json with bash or any other light weight scripting languages. I’ve been playing around with this for about a week and I would like to share some of the features it has.
If you work with a service like ElasticSearch where the keys are never in the
same order this is an amazing feature. I have used it with
vimdiff to wire up
some quick diffs. This example grabs two different documents from ElasticSearch
and shows a side-by-side difference of the two documents. Note how it drills
strait down into the
._source key, which is the data we care about.
variables with the dollar sign
Sometimes what you are trying to extract out is pretty far down. For instance say you are using a pretty wordy hypermedia API that has the users in the structure separate from the comments.
The following will combine the user with the comment
And produce the following output:
Being able to manipulate json into an easily digestible format for scripts gets even better. Using the same example from above:
Produces the following output
There is a ton of features baked into this and I have only scratched the surface. As I run into uses for them I plan to put together a sticky page of recipes I have used. Stay tuned!