jq

CLI>=1.6

Lightweight and flexible command-line JSON processor.

Query and transform JSON on the command line

6 of 7 recipes verified by execution · 2026-09-17#json#filter#transform#query

Verified commands

Executed by our harness on the platforms shown; the assertion checked the actual result, not just the exit code.

Extract a field from a JSON file

Verified macOS · Linux · 2026-09-17
jq -r '.name' package.json
Common failures (1)
  • output is wrapped in quotes-r prints raw strings without JSON quoting

List the keys of an object

Verified macOS · Linux · 2026-09-17
jq -r '.dependencies | keys[]' package.json

Filter an array by a condition

Verified macOS · Linux · 2026-09-17
jq -c '[.[] | select(.active == true) | .name]' users.json

Modify a JSON file in place

Verified macOS · Linux · 2026-09-17
jq '.scripts.test = "vitest"' package.json > package.json.tmp && mv package.json.tmp package.json
Common failures (1)
  • file becomes emptynever redirect jq output to its own input file; write to a temp file then mv

Split an array into one JSON object per line (NDJSON)

Verified macOS · Linux · 2026-09-17
jq -c '.[]' users.json

Pass a shell variable into a filter

Verified macOS · Linux · 2026-09-17
jq -r --arg k react '.dependencies[$k]' package.json
Common failures (1)
  • $k is not defined / nulluse --arg name value and reference it as $name inside the filter

More recipes

Curated from documentation and usage. Percentages are estimates, not measurements.

Pretty-print JSON from an API response

~99% est.
curl -s https://api.example.com/data | jq '.'

Install

Homebrewbrew install jq
aptsudo apt install jq

Agent notes

When to use
Parsing API responses, transforming JSON data, extracting fields
Quick examples
  • echo '{}' | jq '.key'
  • cat data.json | jq '.[] | .name'

Use from an agent

curl -s https://clihub.com/api/tools/jq | jq '.agentHints.provenRecipes[] | {task, command, verified}'

Or call get_tool with slug jq on the MCP server at https://clihub.com/mcp.

Homepage ↗Repository ↗MIT0 views