Lesson 23 of 55
PythonWorking with JSON
20 minutes
Course progress42%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 23 of 55
Python20 minutes
Keep these ideas in mind as you work through the lesson.
JSON (JavaScript Object Notation) is a lightweight data‑exchange format. Python’s json module makes converting between JSON strings and native objects effortless.
import json
# Serialize a Python dict to JSON
data = {'name': 'Alice', 'age': 30}
json_str = json.dumps(data)
print('JSON:', json_str)
# Deserialize back to a dict
loaded = json.loads(json_str)
print('Name from JSON:', loaded['name'])
When working with files, use json.dump() and json.load() to read/write directly.