xxxxxxxxxx
# a Python object (dict):
x = {
"name": "John",
"age": 30,
"city": "New York"
}
# convert into JSON:
y = json.dumps(x)
xxxxxxxxxx
import json
# some JSON:
x = '{ "name":"John", "age":30, "city":"New York"}'
# parse x:
y = json.loads(x)
# the result is a Python dictionary:
print(y["age"])
xxxxxxxxxx
import json
# JSON data
json_data = '{"name": "John", "age": 30, "city": "New York"}'
# Convert JSON data to object
data_object = json.loads(json_data)
# Access object properties
name = data_object['name']
age = data_object['age']
city = data_object['city']
print(name) # Output: John
print(age) # Output: 30
print(city) # Output: New York