How can I create the json string for the below dictionary

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

Answers (1)

Boseong Choi
Boseong Choi

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

Related Questions