In this tutorial, we will learn how to convert a python dictionary to json in python, we will use json package to implement it.
1. Import library
import json
2. Create a python dictionary
my_dict={'website':'cocyer.com','topic':'json and python','year':2019,'list':[10,20,30]}
3. Convert python dictionary to json
json_string=json.dumps(my_dict) print (json_string)
The json string will be:
{"website": "cocyer.com", "topic": "json and python", "year": 2019, "list": [10, 20, 30]}