跳转到主要内容
kitlocal.dev

jq 速查表

本地运行

100% 在你的浏览器中处理。输入和输出绝不会离开你的设备。

基于 jq 1.8 验证的 jq JSON 处理器过滤器、管道、对象构建、数组、select、map、group_by、reduce 与命令行标志。

工作原理

Every jq filter transforms an input JSON stream into zero or more output JSON values. Dot (`.`) is the identity filter; pipes (`|`) pass each output of the left filter into the right filter, and `.[]` explodes an array or object into a stream of items so you can filter, map and re-wrap them with `[...]`.

生存指南

最先需要掌握的少数几个命令。

40 条命令

键盘快捷键/聚焦搜索框JK移动选择C复制选中命令F收藏选中项Esc清空搜索

Inspect & format JSON

Start with `.` to validate and pretty-print JSON, or `-r`/`-c` to adapt formatting for downstream tools.

官方文档:Invoking jq
  • 基础必备

    Validate and pretty-print JSON with syntax highlighting.

    jq . <file.json>

    适用场景

    Quickly format minified API responses or confirm JSON syntax from the terminal.

    命令解析

    .
    identity filter: passes the whole JSON value unchanged

    示例

    echo '{"b":2,"a":1}' | jq -c .

    运行结果

    {"b":2,"a":1}

    替代命令

    • jq -S . <file.json> (sort object keys alphabetically)

    另请参见

Access fields & arrays

Chain property names with `.a.b`, index arrays with `.[0]`, and append `?` to skip missing/null errors.

官方文档:Basic filters

Filter & transform

Combine `select(cond)` to drop items and `map(...)` or `[...]` to transform the remaining ones.

官方文档:Builtin operators & functions

Sort, group & aggregate

Group records by a key, deduplicate, compute totals, or flatten nested arrays.

官方文档:Sorting and grouping

CLI variables, CSV & shell interop

Pass shell parameters safely with `--arg` / `--argjson` and export tables directly with `@csv` or `@tsv`.

官方文档:Format strings and escaping

在 KitLocal 工具中试用

术语表
Filter
An expression in jq that takes a JSON value and outputs zero or more values.
Stream
Multiple values produced by `.[]` or `,` before wrapping back into an array with `[...]`.
Raw output (-r)
Outputs strings without JSON surrounding quotes — essential when feeding bash or grep.
Compact (-c)
Prints each JSON object on a single line (NDJSON / JSON Lines).

核对时间:2026年11月15日 · 核对版本:jq 1.8

来源: jq Manual (jqlang.org)

请将尖括号内的内容替换为你自己的实际值。所有命令均来自官方文档,示例均在标明版本上实测运行。