↑ ↓ select, Enter open, Esc close

Filter a JSON array by a field value

Adjust the values, the command updates live
user@server
jq '[.[] | select(.status == "active")]' plugins.json

Iterates 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

Related one-liners

All in Text processing

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.