How to print Python dictionary into JSON format?

PythonServer Side ProgrammingProgramming

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}'
raja
Published on 29-Dec-2017 13:51:51
Advertisements