From 068e56f0ff298d7b766a5173868e2565a5f9bd1a Mon Sep 17 00:00:00 2001 From: Mark Eaton Date: Wed, 17 Sep 2025 19:14:48 -0400 Subject: [PATCH] refactor: render `response` as plaintext with newlines, fallback to JSON pretty-print Co-authored-by: aider (o3) --- scripts/jsonl_pretty_print.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/jsonl_pretty_print.py b/scripts/jsonl_pretty_print.py index 214b88d..9de79db 100644 --- a/scripts/jsonl_pretty_print.py +++ b/scripts/jsonl_pretty_print.py @@ -50,12 +50,17 @@ def pretty_print_jsonl(path: Path, indent: int) -> None: obj = json.loads(line) except json.JSONDecodeError as exc: sys.exit(f"JSON decode error on line {idx}: {exc}") # fail fast - # Build pretty JSON string, convert literal "\n" sequences to real newlines, - # and emit a blank line between records for readability. - pretty = json.dumps(obj, indent=indent, ensure_ascii=False, sort_keys=True) - pretty = pretty.replace("\\n", "\n") - sys.stdout.write(pretty) - sys.stdout.write("\n\n") + # Prefer rendering the `response` field as plain-text, expanding literal + # "\n" sequences to real newlines. Fall back to JSON pretty-print if the + # key is missing so we still show *something* useful. + if "response" in obj: + response_text = str(obj["response"]).replace("\\n", "\n") + sys.stdout.write(response_text) + sys.stdout.write("\n\n") + else: + pretty = json.dumps(obj, indent=indent, ensure_ascii=False, sort_keys=True) + sys.stdout.write(pretty) + sys.stdout.write("\n\n") def main() -> None: