jq
CLI>=1.6Lightweight and flexible command-line JSON processor.
Query and transform JSON on the command line
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
jq -r '.name' package.jsonCommon failures (1)
- output is wrapped in quotes-r prints raw strings without JSON quoting
List the keys of an object
jq -r '.dependencies | keys[]' package.jsonFilter an array by a condition
jq -c '[.[] | select(.active == true) | .name]' users.jsonModify a JSON file in place
jq '.scripts.test = "vitest"' package.json > package.json.tmp && mv package.json.tmp package.jsonCommon 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)
jq -c '.[]' users.jsonPass a shell variable into a filter
jq -r --arg k react '.dependencies[$k]' package.jsonCommon 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
curl -s https://api.example.com/data | jq '.'Install
Homebrew
brew install jqapt
sudo apt install jqAgent 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.