Work with JSON data.
Source Code
import json
# Convert dictionary to JSON string
data = {"name": "John", "age": 30}
json_str = json.dumps(data)
print(json_str)
# Convert JSON string back to dictionary
data = json.loads(json_str)
print(data)
Work with JSON data.
import json
# Convert dictionary to JSON string
data = {"name": "John", "age": 30}
json_str = json.dumps(data)
print(json_str)
# Convert JSON string back to dictionary
data = json.loads(json_str)
print(data)