Computer >> Computer tutorials >  >> Programming >> Python

How to print Python dictionary into JSON format?


JSON stands for Javascript Standard Object Notation. Python module called json is a JSON encoder/decoder. The dumps() function in this module returns a JSON string representation of Python dictionary object.

D1={"pen":25, "pencil":10, "book":100, "sharpner":5, "eraser":5}
>>> import json
>>> j=json.dumps(D1)
>>> j
'{"pen": 25, "pencil": 10, "book": 100, "sharpner": 5, "eraser": 5}'