Reputation: 31
Can we create the JSON
string for the following dictionary?
dict1 ={'name':'rahul','age':26,'location':'chennai'}
Please suggest me to create the JSON
string.
Upvotes: 3
Views: 33
Reputation: 2596
You can use built-in library json
.
Documentation: https://docs.python.org/3/library/json.html
import json
dict1 = {'name': 'rahul', 'age': 26, 'location': 'chennai'}
json_str = json.dumps(dict1)
print(json_str)
output:
{"name": "rahul", "age": 26, "location": "chennai"}
Upvotes: 3