Skip to main content

Output Formats

Control output format with the --format / -F global flag, available on all commands.

lynxdb query 'level=error | stats count by source' --format table
lynxdb query 'level=error | stats count by source' -F csv

Format Reference

FormatDescriptionAuto-selected when
autoAuto-detect based on context (default)Always the default
jsonPretty-printed JSON (one object per line)Pipe (non-TTY) output
ndjsonNewline-delimited JSON (compact, one object per line)Never auto-selected
tableAligned columns with headers and separatorNever auto-selected
csvRFC 4180 CSV with header rowNever auto-selected
tsvTab-separated values with header rowNever auto-selected
raw_raw field value per line, or tab-separated k=vNever auto-selected

Auto Behavior

The default --format auto adapts based on context:

ContextBehavior
TTY + single scalar resultPlain value (just the number or string)
TTY + multiple resultsColorized JSON with numbered results (#1, #2, ...)
Non-TTY (pipe)json (one JSON object per line)

Examples by Format

json

lynxdb query 'level=error | stats count by source' --format json
{
"source": "nginx",
"count": 340
}
{
"source": "api-gateway",
"count": 120
}

ndjson

lynxdb query 'level=error | stats count by source' --format ndjson
{"source":"nginx","count":340}
{"source":"api-gateway","count":120}

table

lynxdb query 'level=error | stats count by source' --format table
source          count
-------------- -----
nginx 340
api-gateway 120

csv

lynxdb query 'level=error | stats count by source' --format csv
source,count
nginx,340
api-gateway,120

tsv

lynxdb query 'level=error | stats count by source' --format tsv
source	count
nginx 340
api-gateway 120

raw

lynxdb query 'source=nginx | head 3' --format raw
192.168.1.1 - - [14/Feb/2026:14:23:01 +0000] "GET /api HTTP/1.1" 200 1234
192.168.1.1 - - [14/Feb/2026:14:23:02 +0000] "POST /login HTTP/1.1" 302 0
192.168.1.1 - - [14/Feb/2026:14:23:03 +0000] "GET /dashboard HTTP/1.1" 200 5678

Disabling Colors

Colors are enabled by default when output goes to a TTY. Disable them with:

# Flag
lynxdb query 'level=error | stats count' --no-color

# Environment variable (any non-empty value)
NO_COLOR=1 lynxdb query 'level=error | stats count'

Piping and Scripting

When stdout is not a terminal, --format auto produces clean JSON suitable for piping:

# Pipe to jq
lynxdb query 'FROM main | stats count by host' | jq '.host'

# Export to file
lynxdb query 'FROM main | where level="ERROR"' --since 24h > errors.json

# Export as CSV for spreadsheets
lynxdb query 'FROM main | stats count by host' --format csv > report.csv

# Chain with other tools
lynxdb query '| stats count by status' --format csv | sort -t, -k2 -rn

Metadata to stderr

Stats and summary lines are written to stderr so they do not pollute piped output:

# Only JSON goes to the file; stats go to the terminal
lynxdb query --file access.log '| stats count' > result.json
# stderr shows: Scanned 50,000 events | 1 results | 89ms

See Also