Google News
logo
Convert from Python to JSON
To convert a Python object to a JSON string, you can use the `json.dumps()` function. Here is an example :
Program :
import json

my_dict = {"name": "John", "age": 30, "city": "New York"}

json_str = json.dumps(my_dict)

print(json_str)
Output :
{"name": "John", "age": 30, "city": "New York"}
Note that the resulting JSON string contains double quotes around the keys and string values.