Ir para o conteúdo principal
kitlocal.dev

Cheatsheet do jq

Roda localmente

100% processado no seu navegador. Entradas e saídas nunca saem do seu dispositivo.

Filtros do processador JSON jq, pipes, construção de objetos, arrays, select, map, group_by, reduce e flags de CLI verificados no jq 1.8.

Como funciona

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 `[...]`.

Kit de sobrevivência

Os principais comandos para aprender primeiro.

40 comandos

Atalhos de teclado/Focar buscaJKMover seleçãoCCopiar selecionadoFFavoritar selecionadoEscLimpar busca

Inspect & format JSON

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

Documentação oficial: Invoking jq
  • Essencial

    Validate and pretty-print JSON with syntax highlighting.

    jq . <file.json>

    Quando usar

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

    Detalhamento

    .
    identity filter: passes the whole JSON value unchanged

    Exemplo

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

    Resultado

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

    Também funciona

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

    Veja também

Access fields & arrays

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

Documentação oficial: Basic filters

Filter & transform

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

Documentação oficial: Builtin operators & functions

Sort, group & aggregate

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

Documentação oficial: Sorting and grouping

CLI variables, CSV & shell interop

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

Documentação oficial: Format strings and escaping

Experimente em uma ferramenta do KitLocal

Glossário
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).

Verificado em 15 de nov. de 2026 · Verificado na versão jq 1.8

Fontes: jq Manual (jqlang.org)

Substitua qualquer item entre colchetes angulares pelos seus próprios valores. Os comandos vêm da documentação oficial e os exemplos foram executados na versão indicada.