//test.json
{
"RED":
[
{
"attr1": "aaaa",
"attr2": "bbbb",
"attr3": "cccc"
},
{
"attr1": "aaaa",
"attr2": "dddd",
"attr3": "eeee"
}
],
"WHITE":
[
{
"attr1": "aaaa",
"attr2": "bbbb",
"attr3": "cccc"
},
{
"attr1": "aaaa",
"attr2": "dddd",
"attr3": "eeee"
}
]
}
I want to get a value that meets (key=RED && attr1="aaaa" && attr2="bbbb")
So I have written jq command like this :
jq -r 'with_entries(select([.key] | inside(["RED"]))) | .[] | .[] | select(.attr1=="aaaa") | select(.attr2=="bbbb") | .attr3' test.json
this command works well. but I think that command is a little long. How can I shorten the command without reducing readability? (* This is my first time using JQ)