Intermediate
Save and load JSON safely
Write save_json(path, data) that writes data to the file as JSON with indent=2, in UTF-8, keeping non-English letters as they are (ensure_ascii=False).
Write load_json(path, default=None) that reads the JSON back. It returns default if the file does not exist or does not contain valid JSON.
What Check tests
- A round trip returns the same data
- A missing file gives the default
- Invalid JSON gives the default
- Letters like é are written as they are
- An empty file gives the default
- A stored falsy value is returned, not the default
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.