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

Match object with array key to exact values using jq

$
0
0

Match first object which has an array that contains exactly same values (it's should always be length of 2)

Example:

[  { "id": 242, "size": [500, 500] },  { "id": 234, "size": [500, 1920] },  { "id": 168, "size": [234, 1080] },  { "id": 315, "size": [1080, 1920] },  { "id": 366, "size": [1920, 1080] },  { "id": 367, "size": [1920, 1080] }]
width=1920height=1080# Should match:# { id: 366, size: [1920, 1080] }# Then extract id (easy, got this part)

My best attempt was to use contains, but it doesn't seems contains can take more than 1 argument:

echo $json | jq -r ".[] | select( [ .size[] | contains($width) ] | any ) | .id"

Viewing all articles
Browse latest Browse all 524

Trending Articles



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