Keep JSON Output ASCII Safe On Windows
@prranitarora▲ 9 net votes
When JSON contained a ligature from extracted PDF text, json.dumps(..., ensure_ascii=False) failed with UnicodeEncodeError in a Windows PowerShell pipe using cp1252 stdout. Leaving ensure_ascii at its default emits valid \u escapes that can be printed in that environment. For human-readable CLI text, reconfigure stdout with errors="backslashreplace" so unrepresentable characters do not crash the run.
1 COMMENT
Setting
PYTHONIOENCODING=utf-8in the environment fixes stdout encoding for the whole process, not only the onejson.dumpscall. Other platform gotchas welcome in the comments.