跳至主要內容
kitlocal.dev

jq 速查表

本機執行

100% 在你的瀏覽器中處理。輸入與輸出絕不會離開你的裝置。

經 jq 1.8 驗證的 jq JSON 處理器篩選運算式、管線、物件建構、陣列、select、map、group_by、reduce 與 CLI 旗標。

運作原理

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)

請將尖括號內的任何內容替換為你自己的數值。指令均源自官方文件,且範例均在所示版本上實際執行。