Cookbook¶
iq renders JSON-family formats only, no CSV and no tables, by design. Its
output is meant to compose, so you can pipe it into other tools.
Piped input¶
Stdin becomes the source only when nothing else resolves. An active source wins over the pipe.
--from-format forces the decode when the content cannot be sniffed (a gzipped
or oddly-shaped dump).
sq¶
sq is a command-line tool giving jq-style access to SQL
databases and files like CSV or Excel.
SQL → NoSQL¶
sq emits one JSON object per row (-J). iq keys each by the named field.
Foreign JSON always needs --key-field or --key (see
Key mapping).
NoSQL → SQL¶
Piped data is sq's .data table, and the destination table is created if
missing.
CSV or Excel¶
iq --src books '.[]' --jsonl | sq -C .data
iq --src books '.[]' --jsonl | sq -x .data -o books.xlsx
iq itself renders no CSV. sq is the tabular bridge.
quicktype¶
quicktype generates strongly-typed
models and serializers from JSON, JSON Schema, TypeScript, and GraphQL queries.
iq --src books '.[]' --jsona | quicktype -l typescript --top-level Book -o book.ts
The schema-fed variant (iq schema … | quicktype -s schema, see
Schema) types the whole inferred shape. This one
types what a query returned. Pipe a bounded result, not a scan of a
huge keyspace.
gron¶
gron transforms JSON into discrete
assignments to make it easier to grep for what you want and see the absolute
path to it.
-G (grona) indexes results as json[N], so
gron's --ungron rebuilds a JSON array.
-g roots every result at json and is for grepping only.
Miller¶
mlr is like awk, sed, cut, join, and
sort for data formats such as CSV, TSV, JSON, JSON Lines, and
positionally-indexed.
JSONL → CSV¶
Drift guard¶
iq diff follows diff(1): exit 0 when the sources match, 1 when they differ.
As a result, it slots into a cron job or a pre-deploy check as-is.