The json
module already implements some basic pretty printing with the indent
parameter:
>>> import json
>>>
>>> your_json = '["foo", {"bar":["baz", null, 1.0, 2]}]'
>>> parsed = json.loads(your_json)
>>> print json.dumps(parsed, indent=4, sort_keys=True)
[
"foo",
{
"bar": [
"baz",
null,
1.0,
2
]
}
]
SOURCE: http://stackoverflow.com/questions/12943819/how-to-python-prettyprint-a-json-file
Advertisements