Skip to content

Add --color-field for per-value highlighting#3454

Open
omdxp wants to merge 1 commit intojqlang:masterfrom
omdxp:feat/color-field-highlighting
Open

Add --color-field for per-value highlighting#3454
omdxp wants to merge 1 commit intojqlang:masterfrom
omdxp:feat/color-field-highlighting

Conversation

@omdxp
Copy link

@omdxp omdxp commented Dec 16, 2025

Adds a new CLI option to colorize object string values based on key=value rules, intended for structured log fields like level. Includes docs updates, a manpage regen, and tests.

Adds a new CLI option to colorize object string values based on key=value rules, intended for structured log fields like level. Includes docs updates, a manpage regen, and tests.
@omdxp
Copy link
Author

omdxp commented Dec 16, 2025

What this adds

New CLI flag: --color-field key=value:SGR
It forces a specific ANSI color for matching string values (by key + exact value), on top of jq’s normal -C coloring.

Example (realistic app logs)

Input (NDJSON):

{"time":"2025-12-16T23:11:01Z","level":"debug","msg":"starting server"}
{"time":"2025-12-16T23:11:02Z","level":"info","msg":"request","status":200}
{"time":"2025-12-16T23:11:03Z","level":"warn","msg":"slow query","duration_ms":842}
{"time":"2025-12-16T23:11:04Z","level":"error","msg":"upstream timeout","attempt":3}

Command:

jq -c \
  --color-field 'level=debug:0;36' \
  --color-field 'level=info:0;32' \
  --color-field 'level=warn:1;33' \
  --color-field 'level=error:1;31' \
  '.'

Expected terminal appearance (approx):

  • DEBUG: "debug" (cyan)
  • INFO: "info" (green)
  • WARN: "warn" (yellow)
  • ERROR: "error" (red)

Raw ANSI proof (same output, escape bytes visible):

  • debug: \x1b[0;36m"debug"\x1b[0m
  • info: \x1b[0;32m"info"\x1b[0m
  • warn: \x1b[1;33m"warn"\x1b[0m
  • error: \x1b[1;31m"error"\x1b[0m

Notes

  • --color-field implies -C (so it still works when piped).
  • -M overrides and disables all color output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant