Python: JSON prettyprint (dump)

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
        ]
    }
]

 

SOURCEhttp://stackoverflow.com/questions/12943819/how-to-python-prettyprint-a-json-file

Advertisements

PrettyPrint

Prettyprint (or pretty-print) is the application of any of various stylistic formatting conventions to text files, such as source code, markup, and similar kinds of content. These formatting conventions can adjust positioning and spacing (indent style), add color and contrast (syntax highlighting), adjust size, and make similar modifications intended to make the content easier for people to view, read, and understand. Prettyprinters for programming language source code are sometimes called code beautifiers or syntax highlighters (Wikipedia).

JSON Pretty Print: http://jsonprettyprint.com/

Another JSON Pretty Print: http://www.prettyprint.net/

XML Pretty Print: http://xmlprettyprint.com/