Skip to content

jq

Created: 2018-11-13 15:45:46 -0800 Modified: 2019-10-14 09:52:43 -0700

  • You can install this for any OS via their GitHub link.
  • JQ is a JSON parser. It’s like XPATH for JSON.
  • You can quickly try sample inputs/outputs in their sandbox: https://jqplay.org/
    • This is especially helpful because it gives you the command line as output at the bottom.
  • To strip the resulting quotation marks from the string, use “—raw-output” or “-r” (reference).

Goal: figure out the ListenerArn of the object whose port is 8079 (i.e. get “arn_bar”):

{
"Listeners": [
{
"Port": 443,
"ListenerArn": "arn_foo"
},
{
"Port": 8079,
"ListenerArn": "arn_bar"
},
{
"Port": 4873,
"ListenerArn": "arn_baz"
}
]
}

Final query: .Listeners[] | select(.Port == 8079) | .ListenerArn