jsonStr = json.dumps(myobject.__dict__)
# a Python object (dict):
x = {
"name": "John",
"age": 30,
"city": "New York"
}
# convert into JSON:
y = json.dumps(x)
# if you're not using a class for your json you can just do this
jsonStr = json.dumps(jsn)
# if you want to serialize a class then you need to add the __dict__
jsonStr = json.dumps(jsn.__dict__)
jsonStr = json.dumps(myobject.__dict__)
# a Python object (dict):
x = {
"name": "John",
"age": 30,
"city": "New York"
}
# convert into JSON:
y = json.dumps(x)
# if you're not using a class for your json you can just do this
jsonStr = json.dumps(jsn)
# if you want to serialize a class then you need to add the __dict__
jsonStr = json.dumps(jsn.__dict__)