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

how to get the intersection of two JSON arrays using jq

$
0
0

Given arrays X and Y (preferably both as inputs, but otherwise, with one as input and the other hardcoded), how can I use jq to output the array containing all elements common to both? e.g. what is a value of f such that

echo '[1,2,3,4]' | jq 'f([2,4,6,8,10])'

would output

[2,4]

?

I've tried the following:

map(select(in([2,4,6,8,10])))  --> outputs [1,2,3,4]select(map(in([2,4,6,8,10])))  --> outputs [1,2,3,4,5]

Viewing all articles
Browse latest Browse all 657

Trending Articles



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