json
` module which is included in the standard library in Python. This module provides two methods `dumps()
` and `dump()
` for converting Python objects into JSON strings.import json
# create a dictionary
person = {
"name": "John",
"age": 30,
"city": "New York"
}
# convert dictionary to JSON string using dumps()
json_string = json.dumps(person)
# print JSON string
print(json_string)
{"name": "John", "age": 30, "city": "New York"}
json
` module and created a dictionary called `person
`. dumps()
` method of the `json
` module to convert the dictionary into a JSON string and stored it in a variable called `json_string
`.