Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jq select or statement

Tags:

jq

I have the the following input json:

{
  "TagList": [
    {
      "Key": "Environment",
      "Value": "foo"
    },
    {
      "Key": "ENVIRONMENT",
      "Value": "bar"
    }
  ]
}

I want to get the values of tags with the key ENVIRONMENT using jq:

jq -r '.TagList[] | select(.Key=="ENVIRONMENT") | .Value' input.json

But as it turned out, the key could be also Environment. I try get both using this command:

jq -r '.TagList[] | select((.Key=="ENVIRONMENT") | .Value' or .Key=="Environment" | .Value)

but get the following error:

jq: error: syntax error, unexpected $end, expecting ';' or ')' (Unix shell quoting issues?) at <top-level>, line 1:
.TagList[] | select((.Key=="ENVIRONMENT") | .Value
jq: 1 compile error

How to get both of those tags?

like image 515
eekfonky Avatar asked Aug 24 '26 17:08

eekfonky


1 Answers

You can use the following command:

jq '.TagList[]|select(.Key=="Environment" or .Key=="ENVIRONMENT").Value'
like image 151
hek2mgl Avatar answered Aug 27 '26 00:08

hek2mgl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!