Bug Description
When running notion db query with certain results, the JSON output contains unescaped newline characters, causing JSON parsing to fail.
Root Cause
Some Notion pages have URLs that contain actual newline characters. When json.dumps outputs the JSON with indent=2, the newlines in string values are not being properly escaped.
Evidence
When running through pytest capture, the output becomes corrupted:
json.decoder.JSONDecodeError: Invalid control character at: line 43 column 81 (char 1370)
The raw JSON contains unescaped newlines in URL values.
Suggested Fix
Sanitize string values before JSON output to remove or escape problematic control characters:
def _sanitize_json_value(value):
"""Remove or escape control characters that break JSON parsing."""
if isinstance(value, str):
# Replace problematic control characters
return value.replace('\n', '\\n').replace('\r', '\\r').replace('\t', '\\t')
return value
Or use json.dumps with escapechar parameter, or post-process the output.
File to Fix
src/notion_cli/core/output.py
Bug Description
When running
notion db querywith certain results, the JSON output contains unescaped newline characters, causing JSON parsing to fail.Root Cause
Some Notion pages have URLs that contain actual newline characters. When
json.dumpsoutputs the JSON withindent=2, the newlines in string values are not being properly escaped.Evidence
When running through pytest capture, the output becomes corrupted:
The raw JSON contains unescaped newlines in URL values.
Suggested Fix
Sanitize string values before JSON output to remove or escape problematic control characters:
Or use
json.dumpswithescapecharparameter, or post-process the output.File to Fix
src/notion_cli/core/output.py