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

How to use jq to return length of filtered array?

$
0
0

My json file is called my_locations.json and contains an array called locations. I want to filter this array by all objects that have keys location.is_shop and location.has_parking_space. I then want to return the length of this filtered array.

Here is my attempt using the program jq:

$ jq ".locations[] | select(.is_shop and .has_parking_space) | length" my_locations.json1313131313...13

So it outputs the length of each location object in the array instead of the length of the filtered array.

How can I return the length of the filtered array?


Viewing all articles
Browse latest Browse all 582

Trending Articles



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