I've got a JSON file that looks something like this:
{ "results" : { "groups" : {"alpha" : { "items": {
"apple" : { "attributes": { "class": "fruit" } },
"pear" : { "attributes" : { "class": "fruit" }},
"dog" : {"attributes" : {"class": null }}
}},
"beta": {"items": {
"banana" : { "attributes": { "class": "fruit" } }
}}}}}
I want to find keys of items where class is null. I cannot figure out how to do this using jq.
Something like
. as $object | keys[] | select($object[.].class == null)
should do the trick. The . as $object saves the input in $object, which you can refer to later to select specific keys.
Most helpful comment
Something like
should do the trick. The
. as $objectsaves the input in $object, which you can refer to later to select specific keys.