
python-json
UTF-8 JSON file I/O utilities to avoid Windows encoding issues (CP-1252 vs UTF-8)
by lawless-m|Open Source
Python JSON
Python's open() uses the system encoding, which on Windows is CP-1252, not UTF-8 — so reading/writing JSON that contains £, €, or accented letters produces mojibake and violates RFC 8259 (JSON must be UTF-8). Two rules fix it:
- Always pass
encoding='utf-8'when opening a JSON file. - Always pass
ensure_ascii=Falsewhen writing, so Unicode stays readable instead of becoming\uXXXX.
Convention
Every Python project here that touches JSON gets a copy of json_io.py (in this skill directory) dropped into its utils/, then imports from it instead of calling json.load/json.dump directly:
from utils.json_io import load_json, save_json
data = load_json('config.json')
save_json('output.json', {'price': '£99.99'})
json_io.py is already correct — copy it, don't rewrite it.
Symptom → fix
£,€,éappearing in data → a UTF-8 file was read as CP-1252; addencoding='utf-8'(or useload_json).£in written output →json.dumpdefaulted toensure_ascii=True; passensure_ascii=False(or usesave_json).