import json
# Dictionary representing data
data = {'name': 'John', 'age': 30, 'city': 'New York'}
# Serialize (convert to JSON)
json_string = json.dumps(data)
# To parse JSON data (deserialize)
parsed_data = json.loads(json_string)
code
JSON Serialization and Deserialization
This Python code demonstrates JSON serialization (converting a Python dictionary to a JSON string) using json.dumps and JSON deserialization (parsing a JSON string back to a Python dictionary) using json.loads. The comments provide explanations for each part of the code.
JSON
Serialization
Deserialization