L5·Intermediate/Advanced
📤JSON & Serialization
Turning objects into text and back.
jsonpickleserialization
§ 1json module
json.dumps(obj) → str, json.loads(s) → obj. json.dump/load for file objects.
§ 2Custom types
Default only supports dict, list, str, int, float, bool, None. Use default= or a custom Encoder for the rest.
Example
1import json2data = {"name": "Ada", "skills": ["math", "code"], "active": True}3s = json.dumps(data, indent=2)4print(s)5print(json.loads(s))Try it live · Python runs in your browser
Loading playground…
Checkpoint quiz
Question 1 / 2
json.dumps returns: