Step: Filter with select()

Filter with select()

select(condition) passes its input through only when the condition is true, and emits nothing otherwise. Combine it with .[] to filter a stream.

.[] | select(.active)
.[] | select(.name == "Widget")

Why it matters: select is jq's WHERE clause — the workhorse of real queries.

Your turn: keep only products whose price is greater than 20.

Input:
[
  {
    "name": "Widget",
    "price": 25,
    "category": "tools"
  },
  {
    "name": "Gadget",
    "price": 80,
    "category": "tools"
  },
  {
    "name": "Notebook",
    "price": 12,
    "category": "office"
  },
  {
    "name": "Pen",
    "price": 3,
    "category": "office"
  }
]
Expected:
{
  "name": "Widget",
  "price": 25,
  "category": "tools"
}
{
  "name": "Gadget",
  "price": 80,
  "category": "tools"
}
Step 17 of 27