Vai al contenuto principale
kitlocal.dev

Cheatsheet jq

Esecuzione locale

Elaborazione al 100% nel tuo browser. Input e output non lasciano mai il tuo dispositivo.

Filtri del processore JSON jq, pipe, costruzione di oggetti, array, select, map, group_by, reduce e flag CLI verificati su jq 1.8.

Come funziona

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 di sopravvivenza

I pochi comandi da imparare per primi.

40 comandi

Scorciatoie da tastiera/Attiva ricercaJKSposta selezioneCCopia selezionatoFAggiungi selezionato ai segnalibriEscCancella ricerca

Inspect & format JSON

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

Documentazione ufficiale: Invoking jq
  • Essenziale

    Validate and pretty-print JSON with syntax highlighting.

    jq . <file.json>

    Quando usarlo

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

    Dettaglio

    .
    identity filter: passes the whole JSON value unchanged

    Esempio

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

    Risultato

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

    Funziona anche

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

    Vedi anche

Access fields & arrays

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

Documentazione ufficiale: Basic filters

Filter & transform

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

Documentazione ufficiale: Builtin operators & functions

Sort, group & aggregate

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

Documentazione ufficiale: Sorting and grouping

CLI variables, CSV & shell interop

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

Documentazione ufficiale: Format strings and escaping

Provalo in uno strumento di KitLocal

Glossario
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).

Verificato il 15 nov 2026 · Verificato sulla versione jq 1.8

Fonti: jq Manual (jqlang.org)

Sostituisci gli elementi tra parentesi angolari con i tuoi valori. I comandi provengono dalla documentazione ufficiale e gli esempi sono stati eseguiti sulla versione indicata.