Code examples from Python Tutorial - Lesson 18: Working with JSON.
| File | Description |
|---|---|
json_basics.py |
JSON serialization with dumps, parsing with loads, pretty printing, type mappings |
json_files.py |
Reading and writing JSON files with dump and load |
data_manager.py |
Mini project: contact manager with custom datetime serializer |
python3 json_basics.py
python3 json_files.py
python3 data_manager.pyjson.dumps()- Convert Python objects to JSON stringsjson.loads()- Parse JSON strings to Python objectsjson.dump()- Write JSON directly to filesjson.load()- Read JSON directly from files- Pretty printing with
indentparameter - Type mappings:
True/true,None/null,False/false - Custom serializers with the
defaultparameter - Handling
datetimeobjects in JSON