sincecutoff.com
← all changes

stern extractJSONParts supports nested JSON fields with dot notation

Introduced 2026-10-22 · score 0.98

HOW TO USE IT

When formatting JSON log messages, use Stern’s template functions with dot notation to extract fields nested in JSON objects. For example, extract `python.levelname` from `.Message` with `extractJSONParts`.

stern --template='{{ extractJSONParts .Message "python.levelname" "message" }}{{"\n"}}' backend
stern --template='{{ extractJSONParts .Message "python.levelname" }}{{"\n"}}' backend

WHY THIS HELPS

When formatting JSON log messages, extract fields nested inside JSON objects.

BEFORE THIS CHANGE

For nested JSON fields, `extractJSONParts` and `tryExtractJSONParts` did only a flat top-level key lookup, so a dotted key rendered as `<nil>`.

REQUIREMENTS AND LIMITATIONS

  • Version: v1.35.0
  • --template: Custom Go template applied to each log message.
  • .Message (required): String passed to the extraction function for JSON parsing.
  • extractJSONParts (required): Parses the input string as JSON and concatenates the specified keys; keys may use dot notation to access nested fields.
  • tryExtractJSONParts: Attempts JSON parsing and concatenates the specified keys using dot notation for nested fields; returns the text on failure.
  • <pod-query> (required): Positional pod query; the documented example uses `backend`.
  • A literal top-level key is tried first, preserving existing flat-key usage, including keys that already contain a dot.

FIRST-PARTY EVIDENCE

Check the installed version and the source before using it. Entry JSON

Report a problem with this card