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

Filter nodes by array value #43

Closed
palmerabollo opened this issue Nov 16, 2016 · 2 comments
Closed

Filter nodes by array value #43

palmerabollo opened this issue Nov 16, 2016 · 2 comments

Comments

@palmerabollo
Copy link

Given a JSON such as:

[
  {
     "type": ["a", "b"]
  },
  {
     "type": ["c"]
  }
]

I can't figure out how to get all nodes where type=='c'? Is there a 'contains value' operator or something like that?

Thanks.

@dchester
Copy link
Owner

There is no such "contains value" operator, but you could get there with a filter expression:

var nodes = jp.nodes(data, '$..[?(@.type.indexOf("c") > -1)]')
// [ { type: ['c'] } ]

@palmerabollo
Copy link
Author

palmerabollo commented Nov 17, 2016

Thank you. Worked like a charm.

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

No branches or pull requests

2 participants