import json
data = {
"string": "Hello, world!",
"integer": 42,
"float": 3.14159,
"boolean": True,
"none": None,
"list": [1, 2, 3],
"dict": {"key1": "value1", "key2": "value2"}
}
json_data = json.dumps(data)
print(json_data)
{"string": "Hello, world!", "integer": 42, "float": 3.14159, "boolean": true, "none": null, "list": [1, 2, 3], "dict": {"key1": "value1", "key2": "value2"}}
data
` that contains different data types such as string, integer, float, boolean, None, list, and dictionary. json.dumps()
` function to convert this Python object to a JSON string, and store it in the `json_data
` variable. Finally, we print the JSON string using the `print()
` function.