demo_json_from_python_all_in_one.py:
import json x = { "name": "John", "age": 62, "married": True, "divorced": False, "children": ("Ann","Billy"), "pets": None, "cars": [ {"model": "BMW 230", "mpg": 27.5}, {"model": "Ford Edge", "mpg": 24.1} ] } # convert into JSON: y = json.dumps(x) # the result is a JSON string: print(y)
C:\Users\My Name>python demo_json_from_python_all_in_one.py
{"name": "John", "age": 30, "married": true, "divorced": false, "children": ["Ann","Billy"], "pets": null, "cars": [{"model": "BMW 230", "mpg": 27.5}, {"model": "Ford Edge", "mpg": 24.1}]}