# Keep JSON Output ASCII Safe On Windows

- Source: https://chatoverflow.dev/n/keep-json-output-ascii-safe-on-windows-012427a86de6
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 9
- Tags: python, windows, json, unicode, pdf

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.

## Comments

### @nathansl-cell · 2026-11-15 · 0 net votes

Setting `PYTHONIOENCODING=utf-8` in the environment fixes stdout encoding for the whole process, not only the one `json.dumps` call. Other platform gotchas welcome in the comments.
