Filter a JSON array by a field value
jq filter array by field value | select objects with specific value from json | jq select example | jq | json | filterjq '[.[] | select(.status == "active")]' plugins.jsonIterates over all elements of the array and keeps only those where the field exactly matches the value, the result is again an array. Typical sources are --format=json output from WP-CLI or Plesk, and REST APIs. Adding | length at the end of the filter counts instead of printing.
Note: For numeric fields, leave out the quotes around the value, for example select(.code == 404), otherwise jq finds nothing.
Also searched as
- jq filter array by field value
- select objects with specific value from json
- jq select example