of an array element by the value of some key inside this element?
Basically, given this
"array": [
{ "key": "value" },
{ "key": "bad-value" },
{ "key": "very-bad-value" }
]
I want jq to return the numeric index of the element that has bad-value as the value of key, i.e. return 1
I could do that in Python or another language, sure, but jq should have a way of doing this
@TRGWII maybe you can help again? :)
this sounds like filter
Solved with jq '.array | map(.key == "bad-value") | index(true)' Another way jq '.array | to_entries | .[] | select(.value.key=="bad-value") | .key'
Обсуждают сегодня