Junior — Middle
Explain the concept of data transformation into a format suitable for storage or transmission
sobes.tech AI
Answer from AI
Data transformation into a format suitable for storage or transmission is called serialization. It is the process of converting objects or data structures into a sequence of bytes or text that can be saved to a file, database, or transmitted over a network.
The reverse process — deserialization — restores the object from this format.
Examples of formats: JSON, XML, YAML, binary formats.
In Python, the json module is often used for serialization:
import json
data = {'name': 'Alice', 'age': 30}
serialized = json.dumps(data) # Converts to a JSON string
# To write to a file
with open('data.json', 'w') as f:
json.dump(data, f)
# To read and deserialize
with open('data.json') as f:
loaded_data = json.load(f)
Serialization is important for data exchange between systems, saving state, and caching.