CLI Reference
aq [OPTIONS] [EXPRESSION] [FILES]...- With no
EXPRESSION,aqruns.. - With no
FILES,aqreads stdin. Use-to read stdin explicitly alongside files; it may appear at most once. - Results are a jq-style stream: each result is printed separately and nothing is collected into an array unless you ask for it with
--slurp. - JSON and JSONL inputs are evaluated one value at a time as they are parsed, like jq. If a later value is malformed, the results for earlier values are printed first and then
aqexits with status 5. Other formats are parsed in full before evaluation starts. TOML and table output wait for every result, since they render all results together. - A runtime error, such as
error(...)or adding a string to a number, is printed and evaluation moves on to the next input, as in jq. Only a parse error stops reading input. - JSONL input over 4 MB is evaluated on every core when the query handles each input on its own: no
input,inputs, ordebug, no-sor-n, and JSON or JSONL output. Results and errors come out exactly as they would on one thread.
Formats
| Format | Read | Write | Notes |
|---|---|---|---|
json | yes | yes | Input may be a single value or a whitespace-separated stream of values, like jq. |
jsonl | yes | yes | One value per line; blank lines are ignored. |
yaml | yes | yes | Multi-document input and output. Scalar mapping keys such as 200: are read as strings. .inf/.nan are floats. |
toml | yes | yes | Output must be exactly one object. Local dates, times, and datetimes round-trip as TOML values and render as strings in other formats. |
csv | yes | yes | Each row is an array of strings. Each output result must be an array of scalars. |
tsv | yes | yes | Like CSV, with backslash escapes for tab, newline, carriage return, and backslash. |
table | no | yes | Human-readable output only. Objects become keyed columns, arrays indexed columns, scalars a single value column. |
Choosing the input format
-p/--input-format forces a reader. Otherwise aq uses the file extension and falls back to sniffing the content. When the extension and the content disagree, --detect-conflicts (or AQ_DETECT_CONFLICTS) decides:
| Policy | Behavior |
|---|---|
warn-fallback (default) | Parse with the extension's format. Only if that fails, warn and use the sniffed format. |
extension | Always use the extension's format. |
sniff | Always use the sniffed format. |
Stdin has no extension, so it is always sniffed. Input that starts with { or [ and has no YAML --- line is read as JSON (or JSONL, when every line is a record); if its first value fails to parse, detection falls back to the full sniffer. The sniffer checks for JSONL, a JSON value stream, TOML, multi-row TSV and CSV, and otherwise reads YAML.
Choosing the output format
-o/--output-format picks the writer. Without it, aq writes the input format when all inputs share one, and JSON otherwise.
Shape rules:
json,jsonl, andyamlcan emit any number of results.tomlrequires exactly one object result.csvandtsvtreat each result as one row and require arrays of scalars.tablerejects-r,-j, and--raw-output0.
CSV and TSV values
--tabular-coercion strings (the default) keeps every cell as a string, so zip codes and IDs survive untouched. --tabular-coercion infer-scalars turns cells that are exact JSON scalars (true, null, 1.25) into those values.
aq -o json -c . people.csv # ["1","alice"]
aq -o json -c --tabular-coercion infer-scalars . people.csv # [1,"alice"]Input options
| Flag | Meaning |
|---|---|
-p, --input-format <FMT> | Force the input reader. (-f FMT still works when no file named FMT exists, with a deprecation warning.) |
-f, --from-file FILE | Read the query from FILE, as jq does. The first positional argument is then an input file. |
-s, --slurp | Read every input document into one array before evaluating. |
-R, --raw-input | Treat each input line as a string. |
-n, --null-input | Evaluate once against null. File arguments stay readable through input/inputs; stdin is read only if the query uses them. |
--stream | Turn each input into jq's [path, leaf] events, as tostream does. |
--seq | Accept RFC 7464 input (each value preceded by RS, 0x1e) and write RS before each JSON result. |
--line-stream | Evaluate JSONL or --raw-input one line at a time as it arrives; see below. |
--tabular-coercion <MODE> | strings or infer-scalars for CSV/TSV input. |
Output options
| Flag | Meaning |
|---|---|
-o, --output-format <FMT> | Output writer. |
-c, --compact | Compact rendering where the format supports it. |
-r, --raw-output | Print strings without JSON quoting. |
-j, --join-output | Raw output with no newline between results. |
--raw-output0 | Raw output with each result terminated by NUL. |
-S, --sort-keys | Sort object keys. |
--indent <N> / --tab | JSON indentation; --indent -1 means tabs. |
-a, --ascii-output | Escape every non-ASCII character as \uXXXX. As in jq, strings print as JSON even with -r. |
--unbuffered | Flush after each result. |
-C, --color-output / -M, --monochrome-output | Force or disable color. Color is automatic on a TTY unless NO_COLOR is set. |
Numbers keep their written precision: big integers and long decimals are not rounded through doubles. As in jq 1.8, infinities print as ±1.7976931348623157e+308 and NaN prints as null.
Query variables
These work like jq's flags of the same names: --arg NAME VALUE, --argjson NAME JSON, --rawfile NAME PATH, --slurpfile NAME PATH, and --args / --jsonargs to turn the remaining arguments into $ARGS.positional. -L, --library-path DIR adds a directory to the module search path for import and include.
In-place rewrites
-i, --in-place rewrites each file argument with the query's result.
- Every file is evaluated and rendered first. Files are replaced only if all of them succeed, so a bad file leaves every file untouched.
- Each file is written to a temporary file next to it and renamed into place. The original permissions are kept.
- A symlink is followed: the target file is rewritten and the link stays a link.
- A query that produces no results is an error and the file is left unchanged.
- JSON and TOML rewrites need exactly one result; YAML can write several documents.
- Comments and formatting are not preserved.
-irejects raw output modes,tableoutput,-e, and stdin.
aq -i '.version = "2.0"' Cargo.toml
aq -i 'del(.metadata.annotations)' k8s/*.yamlStreaming
--line-stream evaluates the query once per JSONL line (or per raw line with -R) and prints results as it goes, so it works on unbounded input. The full query language is available inside each record. It rejects input/inputs, --null-input, and YAML, TOML, or table output.
tail -f access.jsonl | aq --line-stream -c 'select(.status >= 500) | {path, status}'Exit status
| Code | Meaning |
|---|---|
0 | Success. |
1 | With -e: the last result was false or null. Also unsupported flag combinations and other general errors. |
2 | Unknown flag or invalid flag value, or a file could not be read or written. |
3 | The expression failed to parse. |
4 | With -e: there were no results. |
5 | The last input failed with a runtime error (error(...), a failed operation), or input could not be parsed. |
These match jq. Writing into a closed pipe, as in aq . big.json | head, exits 0 silently.
Environment
| Variable | Meaning |
|---|---|
AQ_FLAGS | Shell-style flags prepended to the command line, e.g. AQ_FLAGS="-c -S". |
AQ_DETECT_CONFLICTS | Default for --detect-conflicts. |
NO_COLOR | Disable automatic color. |
Other options
--explainprints the parsed query and exits.-e, --exit-statussets the exit code from the last result (see above).--generate-completions <SHELL>prints completions for bash, zsh, fish, elvish, or PowerShell.-F,-P,--starlarkand the other--starlark-*flags are covered in Starlark.
aq-specific builtins
On top of jq's builtins, aq adds a few conveniences:
| Group | Builtins |
|---|---|
| Conversion | to_number, to_bool, to_datetime |
| Statistics | avg, median, stddev, percentile(p), histogram(n) |
| Collections | take(n), skip(n), columns, uniq_by(f), sort_by_desc(f), count_by(f) |
| Objects | merge(obj), merge_all(deep), drop_nulls, sort_keys, pick(paths), omit(paths), rename(path; name) |
| Format metadata | yaml_tag, csv_header, xml_attr |
aq -c '[.[] | .age] | {avg: avg, p90: percentile(90)}' users.json
aq --slurp 'merge_all(true)' base.yaml env.yaml local.yaml
aq -c '.[] | omit(.password)' users.json