← 返回 CLI 目录 抓取的
jq
$ jq 社区开源 低风险 jqlang (OSS) · 数据库与数据处理 · MIT · macos / linux / windows
jq 是通用的 Unix 管道伴侣,让 AI Agent 在数据进入上下文窗口之前就能在 Shell 管道中对大体积 JSON 响应做字段切片、重组与聚合。离线、确定性且零外部依赖。
FCRS-1.0 综合评分
97 /100
极佳 (Excellent)
高置信度 (实测)
零摩擦安装命令
brew install jq CLI vs MCP 选型建议 仅 CLI 可用
jq 直接在本地 Shell 管道里裁剪其他 CLI 或 curl 返回的臃肿 JSON——让几乎所有 CLI 的 Token 效率再翻倍。
Agent 友好度体检单
本地探针实测证据 ✓ 原生 JSON 输出
✓ 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
✓ 只读模式开关
✓ 支持 NO_COLOR
— 自省/Schema 发现
— 官方 SKILL.md
实测版本
jq-1.7.1-apple
冷启动耗时
8 ms
退出码 (help / 非法参数)
0 / 2
NO_COLOR 无色码污染 / 无 TTY 不挂起
Yes / Safe
抓取的 --help 摘要
jq - commandline JSON processor [version 1.7.1-apple]
Usage: jq [options] <jq filter> [file...]
jq [options] --args <jq filter> [strings...]
jq [options] --jsonargs <jq filter> [JSON_TEXTS...]
jq is a tool for processing JSON inputs, applying the given filter to
its JSON text inputs and producing the filter's results as JSON on
standard output.
The simplest filter is ., which copies jq's input to its output
unmodified except for formatting. For more advanced filters see
the jq(1) manpage ("man jq") and/or https://jqlang.github.io/jq/.
Example:
$ echo '{"foo": 0}' | jq .
{
"foo": 0
}
Command options:
-n, --null-input use `null` as the single input value;
-R, --raw-input read each line as string instead of JSON;
-s, --slurp read all inputs into an array and use it as
the single input value;
-c, --compact-output compact instead of pretty-printed output;
-r, --raw-output output strings without escapes and quotes;
--raw-output0 implies -r and output NUL after each output;
-j, --join-output implies -r and output without newline after
each output;
-a, --ascii-output output strings by only ASCII characters
using escape sequences;
-S, --sort-keys sort keys of each object on output;
-C, --color-output colorize JSON output;
-M, --monochrome-output disable colored output;
--tab use tabs for indentation;
--indent n use n spaces for indentation (max 7 spaces);
--unbuffered flush output stream after each output;
--stream parse the input value in streaming fashion;
--stream-errors implies --stream and report parse error as
an array;
--seq parse input/output as application/json-seq;
-f, --from-file file load filter from the file;
-L directory search modules from the directory;
--arg name value set $name to the string value;
--argjson name value set $name to the JSON value;
--slurpfile name file set $name to an array of JSON values read
from the file;
--rawfile name file set $name to string contents of file;
--args consume remaining arguments as positional
string values;
--jsonargs consu FCRS-1.0 六维评分拆解
Agent 友好度 24 / 25
天然面向 JSON:支持 -c 紧凑输出、-r 原始字符串、-e 退出码断言,且管道模式下自动关闭色彩输出。
- Supports
-ccompact JSON,-eexit-status mode, andNO_COLOR
安全与权限边界 25 / 25
纯粹的确定性流/文件转换器,零网络调用且不接触任何密钥凭证。
- Offline read-only JSON filter; writes only if shell stdout is redirected
安装与运行摩擦 15 / 15
绝大多数开发机与 CI 镜像默认预装,并覆盖所有主流包管理器。
- Lightweight C binary across macOS, Linux, and Windows
能力覆盖与边际价值 15 / 15
能将标准输出载荷缩小 10x–50x,是 Agent 上下文窗口保护投资回报率最高的工具之一。
- Reduces verbose JSON payloads before entering LLM context
维护与来源背书 9 / 10
由 jqlang/jq 组织以 MIT 协议持续维护 1.7+ 版本。
- Maintained under
jqlangGitHub organization
文档与可验证性 9 / 10
官方手册清晰,且主流大模型对 jq 过滤语法极度熟练。
- Official manual at jqlang.org/manual
安全边界、鉴权与放权指南
鉴权方式
无需鉴权
凭证存储位置
无需任何凭证;仅处理标准输入或本地 JSON 文件。
潜在副作用
只读查询
费用与配额提示
100% 免费、离线运行、MIT 开源。
可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# jq Agent Rules - Pipe large `--json` responses from cloud/SaaS CLIs through `jq -c` to drop unused fields. - Use `jq 'keys'` or `jq '.[0]'` to inspect unknown schemas before printing full arrays.
Agent 高频安全命令配方
只读查询(安全推荐)
将大数组投影为紧凑单行 JSON
cat payload.json | jq -c '[.items[] | {id, name, status}]' 使用 -c 将动辄数 MB 的 JSON 压缩为极简字段对象,大幅节省 Token。
探查未知 JSON 文件的顶层键名
jq 'keys' payload.json
让 Agent 在不打印全文的情况下摸清数据结构。
核心优势
- + 在 Shell 管道中充当万能上下文窗口保护器(
| jq -c)。 - + 零副作用、瞬时启动、输出 100% 确定性 JSON。
- +
-e参数便于在自动化脚本里做布尔/空值退出码判断。
注意事项与踩坑点
- ! 复杂嵌套 jq 表达式在双引号 Shell 字符串中容易转义出错——建议统一用单引号包裹。
已验证兼容的 Agent 宿主
Claude Code Codex CLI Gemini CLI