I'm trying to process some JSON with jq. Specifically, I want a particular key, based on its child value. Example, given:
{
"foo": {"primary": true, "blah": "beep"},
"bar": {"primary": false, "blah": "narf"},
"baz": {"primary": false, "blah": "poink"},
}
I want the string "foo", because that is the key whose child value "primary' is true. (I can guarantee that one and only one entry will have primary = true, due to what's generating the JSON.)
So far the best I've been able to manage is:
jq -r '.[] | select(.primary == true)'
But that returns the value of "foo", not the string "foo" itself. Digging through the manual so far I've not found a way to grab the key specifically.
Any pointers you can provide?