import json
data = {
"name": "John",
"age": 30,
"city": "New York"
}
json_string = json.dumps(data, indent=4)
print(json_string)
{
"name": "John",
"age": 30,
"city": "New York"
}
json.dumps()
` function is used to convert the `data
` dictionary into a JSON string. indent
` parameter is set to 4 to add 4 spaces for each level of indentation.