jq for AI agents
jq for coding agents: pretty-print, filter, and reshape JSON from files and other CLIs, with the one redirect mistake that wipes the input file.
What jq does for an agent
jq is a lightweight command-line JSON processor. It reads JSON from a file or another command, applies a filter, and prints the result, from simple field access to grouping and reshaping.
Agents use it constantly as glue: most agent-ready CLIs can print JSON, and jq turns that into exactly the fields the agent needs, which saves context and tokens.
Official site: jqlang.org
Install jq
The install commands from the official docs. Check it worked with jq --version.
brew install jq
sudo apt-get install jq
winget install jqlang.jq
Signing in jq for an agent
No sign-in. jq only reads the input it is given.
What agents use jq for
Example commands with placeholder names. Swap in your own project, app, or file names.
Pretty-print a JSON file
jq . response.json
Pull one field from every item
jq -r '.items[].name' data.json
Keep only matching objects
jq '[.[] | select(.status == "failed")]' results.json
Count items
jq 'length' data.json
Shape another CLI's JSON output
gh pr list --json number,title | jq -r '.[] | "\(.number) \(.title)"'
Safety rules for agents
Safe to run without asking
jq <filter> file.json<command> | jq <filter>
Ask a human first
jq ... > existing-file (replaces the file)
- Never redirect jq output to its own input file (jq ... a.json > a.json); the shell truncates the file first. Write to a temporary file, check it, then move it.
- Use -r for raw strings when piping into other commands, and quote filters in single quotes.
- Filter large JSON down before printing it, to keep the agent's context small.
AGENTS.md or CLAUDE.md snippet
Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.
## jq Use `jq` for reading, filtering, and reshaping JSON output from files and other commands. - Check it is installed with `jq --version`. If it is missing, ask before installing it. - Auth: none needed. - Run without asking (read-only): `jq <filter> file.json`, `<command> | jq <filter>`. - Ask a human first (changes or deletes things): `jq ... > existing-file (replaces the file)`. - Never redirect jq output to its own input file (jq ... a.json > a.json); the shell truncates the file first. Write to a temporary file, check it, then move it. - Use -r for raw strings when piping into other commands, and quote filters in single quotes. - Filter large JSON down before printing it, to keep the agent's context small. - Prefer JSON output where the command supports it, and keep output short.
jq or an MCP server?
No official MCP server. jq is a local utility with no MCP server, and none is needed: any agent with a shell can pipe JSON through it.
Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.
Other Data & text tools
jq questions
How do I install jq?
Homebrew: brew install jq. Other official options: Debian or Ubuntu, Windows (WinGet). Check the install with jq --version, and see the jqlang docs for other platforms.
How does an AI agent authenticate jq?
No sign-in. jq only reads the input it is given. There is nothing to set up: an agent can use it as soon as jq --version succeeds.
Which jq commands are safe for an agent to run?
Commands that only read state are safe to run without asking: jq <filter> file.json; <command> | jq <filter>. Ask a human before anything that changes or deletes something: jq ... > existing-file (replaces the file).
Is there an MCP server for jq?
jq is a local utility with no MCP server, and none is needed: any agent with a shell can pipe JSON through it.