Junior — Middle
What tools or methods have you used to convert data from a serialized form back into objects?
sobes.tech AI
Answer from AI
To convert serialized data back into objects in Python, modules like json and pickle are often used.
json.loads()allows converting a JSON string into corresponding Python objects (dictionary, list, etc.).pickle.loads()restores Python objects from a byte stream serialized withpickle.dumps().
Example with JSON:
import json
json_data = '{"name": "Ivan", "age": 30}'
obj = json.loads(json_data)
print(obj['name']) # Ivan
Example with pickle:
import pickle
serialized = pickle.dumps([1, 2, 3])
obj = pickle.loads(serialized)
print(obj) # [1, 2, 3]
For more complex cases, libraries like marshmallow or pydantic can be used for deserialization with validation.