json Module
The built-in json module serialises Python objects to JSON strings and deserialises JSON into Python objects.
The built-in json module serialises Python objects to JSON strings and deserialises JSON into Python objects.
import json
data = {"name": "Alice", "age": 30, "scores": [95, 87, 92]}
json_str = json.dumps(data)
parsed = json.loads(json_str)
print(type(json_str), type(parsed))
# Pretty print
print(json.dumps(data, indent=2, sort_keys=True))
json.dumps() returns a string; json.dump() writes to a file. Same for loads/load.