jq examples
jq is a command-line JSON processor to parse json format data. You can find the detailed documentation here. And you can try to play it online at jqplay.org. I am listing out few jq command line examples that I found quite useful for day-to-day work 😃.
Let’s try jq with AWS resources api.
To capture the field of “currentVersionUrl”
--raw-output / -r
is the flag used to capture the json string without quotes. It is actually quite useful if you want to use jq in a bash script
To parse the json data with arrary[]
.
To filter json data:
To reformat json data:
Also there is some interesing array[] indexing jq is following. It works similar to iterating over slices in golang. Something like this:
To escape null, you can use //
as the alternative operator:
Oh well, there are much more jq commands you can use, like a MYSQL style of join()
. Documentaion is quite good and you can find it here. Leave a comment if you have more jq questions 😃