How can I preserve Unicode characters when writing JSON in Python?
Quick answer
Python’s json module preserves Unicode text either way. By default, ensure_ascii=True writes non-ASCII characters as escapes such as \u00e9; ensure_ascii=False writes them directly, such as é. To save readable characters reliably, open the file with encoding='utf-8'. Reopen it the same way, load it with json.load(), and compare the result with the original data. [S1][S2]
The question, the details, the next step.
A practical checklist
Keep
ensure_ascii=Truefor escaped non-ASCII text, or setensure_ascii=Falsefor readable characters.Open the output text file with
encoding='utf-8'.Reopen the saved file with
encoding='utf-8'before callingjson.load().Compare the loaded object or text field with the original Python value.
If another application displays unexpected characters, check that application’s encoding expectations.
A few more useful answers
Does `ensure_ascii=False` turn off JSON escaping entirely?
No. It writes non-ASCII characters directly, but the encoder still escapes characters required by JSON syntax and control characters. [S1]
Will escaped Unicode change the value I get after loading the JSON?
Sources
References used for this guide.
- [S1] Python 3.14 json — JSON encoder and decoder docs.python.org · Checked
- [S2] Python 3.15 tutorial: Saving structured data with JSON docs.python.org · Checked
