Python · Daten

JSON-Datei lesen und schreiben

Kompaktes Beispiel für UTF-8-sichere JSON-Verarbeitung.

Python
import json
from pathlib import Path

pfad = Path("daten.json")

with pfad.open("r", encoding="utf-8") as f:
    daten = json.load(f)

daten["bearbeitet"] = True

with pfad.open("w", encoding="utf-8") as f:
    json.dump(daten, f, ensure_ascii=False, indent=2)
PythonJSONDatei
WA