You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: write_json / read_json raise UnicodeEncodeError on Windows for non-cp1252 characters #5665
pio.write_json raises UnicodeEncodeError on Windows when a figure's text contains characters outside the cp1252 default codec. pio.read_json has the matching bug — it reads without specifying an encoding, so a UTF-8 JSON file is decoded with cp1252, mangling non-ASCII text or raising UnicodeDecodeError.
This works on macOS/Linux only because their default encoding is already UTF-8.
Steps to reproduce
importplotly.graph_objectsasgoimportplotly.ioaspiofig=go.Figure(layout_title_text="μ 中文") # Greek mu + CJKpio.write_json(fig, "fig.json")
# UnicodeEncodeError: 'charmap' codec can't encode character 'μ' in position ...: character maps to <undefined>
The figure text contains a character outside cp1252. Common Latin-1 characters (é, ö, °) are inside cp1252 and do not raise — it takes Greek (μ), CJK, or emoji to trigger it.
orjson is installed (the default engine when available). orjson emits real UTF-8, so non-ASCII characters reach write_text unchanged. The pure-Python json engine uses ensure_ascii=True, escaping everything to \uXXXX ASCII, so it never trips the codec.
write_html already handles this correctly with encoding="utf-8" (see #3898). The JSON I/O path was missed.
Activity
emilykl commentedon Jul 22, 2026
Addressed by #5633