Re:JSON on the Command Line with Jq
by NinoScript on Sunday December 22, 2019 @03:06PM
(#21859315)
Jq is a great tool, I wish more people knew about it!
[ Parent
| on HN ]
It's a bit arcane to use, but has proven itself over and over when doing little tasks with AWS CLI returns.
Re:JSON on the Command Line with Jq
by GhettoMaestro on Sunday December 22, 2019 @03:18PM
(#21859375)
Exactly right.
I use jq to mangle get/list requests from AWS (and others) and then recursively hit each element for whatever reason. Without jq none of my workflows in this area would be remotely easy.
TLDR: Learn JQ! It is like sed and grep, but for JSON.
If you're using AWS you're better using the built in option available for the cli. The --query option (and often combined with the --output option) does this, and uses JMESPath. Especially when you're scripting, it eliminates the need for having yet another tool.
Re:JSON on the Command Line with Jq
by dragonwriter on Monday December 23, 2019 @01:35AM
(#21861872)
> If you're using AWS you're better using the built in option available for the cli. The --query option (and often combined with the --output option) does this, and uses JMESPath.
Jq is so much more capable than jmespath that I find myself using jq on the json output of AWS CLI commands more than using the built-in query option. Sure, it requires another tool, but it’a often the best tool for the job.
That's a great point. Leverage --query for good justice.
Unless you need some additional juice, where jq supports actually transforming the return.
Quite arguably a heavier tool, e.g. a boto3 script becomes appropriate where --query falls short.
But options are a great thing to have.
100%
Re:JSON on the Command Line with Jq
by commandlinefan on Sunday December 22, 2019 @06:27PM
(#21860366)
I’ve been using it as a pretty-printer for a while now, it never occurred to me that you could use it to filter items out. In fact, I’ve been piping jq to grep to find things!