xxxxxxxxxx
json_object = json.loads(json_data)
# Indent keyword while dumping the
# data decides to what level
# spaces the user wants.
print(json.dumps(json_object, indent = 1))
# Difference in the spaces
# near the brackets can be seen
print(json.dumps(json_object, indent = 3))
xxxxxxxxxx
>>> import json
>>> print json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
{
"4": 5,
"6": 7
}
xxxxxxxxxx
raw = {'4': 5, '6': 7}
print(json.dumps(raw, indent=4))
# If you want the beautified string:
beautified = json.dumps(raw, indent=4)