The Dual Operations: `loads` vs `dumps`
1. Deserialization (`json.loads()`)
Converts a raw JSON text string into a Python Dictionary or List.
data = json.loads(raw_text)
2. Serialization (`json.dumps()`)
Converts a Python Dictionary into a valid JSON string (with indent formatting).
json_str = json.dumps(data, indent=2)
Quick Summary
- JSON seamlessly maps to Python dictionaries, lists, booleans, and nulls (
None). - Next, we model real-world domains with Object-Oriented Programming (OOP).