json.dump() serializes a Python object and writes the resulting JSON representation directly to a file-like object. JSON is widely used for exchanging data between systems, and the json module provides dump and load methods for processing JSON files. section 9.3.5
Write a Python object to a JSON file
import json with open("tasks.json", "w") as file: json.dump(tasks, file) section 9.3.5
Keep these usage distinctions in mind:
- Use dump for a JSON file and dumps for a JSON string; their calling patterns are closely related. section 9.3.5
- Native Python objects can be serialized, but instances of custom classes are not JSON-serializable by default; provide custom encoding behavior when needed. section 9.3.5


