Lesson 23 of 55 · Python
Working with JSON
Duration: 20 minutes
Lesson 23 of 55 · Python
Duration: 20 minutes
json module makes converting between JSON strings and native objects effortless.\n\npython\nimport json\n\n# Serialize a Python dict to JSON\ndata = {'name': 'Alice', 'age': 30}\njson_str = json.dumps(data)\nprint('JSON:', json_str)\n\n# Deserialize back to a dict\nloaded = json.loads(json_str)\nprint('Name from JSON:', loaded['name'])\n\n\nWhen working with files, use json.dump() and json.load() to read/write directly.\n