Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finding keys where values match #60

Closed
pzb opened this issue Dec 30, 2012 · 1 comment
Closed

Finding keys where values match #60

pzb opened this issue Dec 30, 2012 · 1 comment
Labels

Comments

@pzb
Copy link

pzb commented Dec 30, 2012

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.

@stedolan
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants