Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FILES / CHAPTER 05 / Learn / LESSON 11
JSON on disk:
import json payload = {"theme": "dark", "level": 3} with open("config.json", "w", encoding="utf-8") as f: json.dump(payload, f)
with open("config.json", encoding="utf-8") as f: loaded = json.load(f) print(loaded["theme"])
Invalid JSON → JSONDecodeError. Catch it and print a short message — do not crash the whole script.
--- broken.json ---
{badLearn: json files and JSONDecodeError.
DECISION STANDBY
›