3

I want something like

jq 'select(.x in [2,4])' <<<'[{"x":1}, {"x": 2}, {"x": 3}, {"x": 4}]'
[{"x": 2}, {"x": 4}]

How do I do this?

1 Answer 1

5

Here's an efficient solution that has the advantage of also being simple and concise:

[2,4] as $list
| map(.x as $x | select( any($list[]; . == $x )))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.