Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

In jq, how to select objects where an array contains at least one value (intersection non-empty)

$
0
0

I have input like this:

{ "prop": ["apple", "banana"] }{ "prop": ["kiwi", "banana"] }{ "prop": ["cherry", "orange"] }

How do I print objects where prop contains at least one of kiwi and orange?

(The list of interesting values is longer than just 2, so I'd like to leverage the any function somehow.)

I've tried the following

jq 'select(any(.prop[] | contains(["kiwi", "orange"])))'< input.json

and various variants of the above, but can't figure out the right expressions.


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>