[jq] Use if to filter objects by a condition

Created on November 30, 2026

Use if … then … else … end to choose what a jq filter emits. This example emits each object whose name is Taro. The empty filter emits nothing for the other objects.

echo '[{"name": "Taro", "age": 25},{"name": "Satoshi", "age": 30}]' | jq '.[] | if .name == "Taro" then . else empty end'
{
  "name": "Taro",
  "age": 25
}
jq