How can I serialize/deserialize data using JSON in Python?
How can I serialize/deserialize data using JSON in Python?
How can I serialize/deserialize data using JSON in Python?
solveurit24@gmail.com Changed status to publish February 13, 2025
Use the json module.
- Serialization (Dump to JSON):
import json
data = {"name": "Alice", "age": 30, "city": "New York"}
with open('data.json', 'w') as file:
json.dump(data, file)
Deserialization (Load from JSON):
with open('data.json', 'r') as file:
loaded_data = json.load(file)
print(loaded_data) # Output: {'name': 'Alice', 'age': 30, 'city': 'New York'}solveurit24@gmail.com Changed status to publish February 13, 2025