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, \"b
You need to "split" your object into an array of entries, e.g.
[
{
"key": "foo",
"value": {
"primary": true,
"blah": "beep"
}
}
//...
]
Then you can filter with .value.primary
and map the result with .key
:
to_entries | map(select(.value.primary) | .key)
Returns:
[
"foo"
]
Or to get just the first item of the array: (Thanks @nbari)
to_entries | map(select(.value.primary) | .key)[0]