beautify json python 1

beautify json python

>>> import json
>>> print json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
    "4": 5,
    "6": 7

Here is what the above code is Doing:
1. We import the json module.
2. We print the json.dumps() function, which takes two arguments:
a. The first argument is a dictionary.
b. The second argument is sort_keys=True, which sorts the keys in the dictionary.
c. The third argument is indent=4, which adds indentation to the output.

Similar Posts