Skip to content
CLI tool · Data & text

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.

jqby jqlang
What it is

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

Install jq

The install commands from the official docs. Check it worked with jq --version.

Homebrew
brew install jq
Debian or Ubuntu
sudo apt-get install jq
Windows (WinGet)
winget install jqlang.jq
Auth

Signing in jq for an agent

No sign-in. jq only reads the input it is given.

Common agent tasks

What agents use jq for

Example commands with placeholder names. Swap in your own project, app, or file names.

  1. Pretty-print a JSON file

    jq
    jq . response.json
  2. Pull one field from every item

    jq
    jq -r '.items[].name' data.json
  3. Keep only matching objects

    jq
    jq '[.[] | select(.status == "failed")]' results.json
  4. Count items

    jq
    jq 'length' data.json
  5. Shape another CLI's JSON output

    jq
    gh pr list --json number,title | jq -r '.[] | "\(.number) \(.title)"'
Safety

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.
Agent instructions

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.

AGENTS.md
## 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.
CLI or MCP server?

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.

Same category
All Data & text tools
FAQ

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.