import json
from ezjson import prettyjson
print prettyjson.__doc__
Pretty display json or dictionnary in collapsible format with indents Options are depth: Depth of the json tree structure displayed, the rest is collapsed. By default: 2. max_length: Maximum number of characters of a string displayed as preview, longer string appear collapsed. By default: 20. sort: Whether the json keys are sorted alphabetically. By default: True. max_height: Maxium height in pixels of containing div. By default: 600. Examples: 1/ Python dictionary dic = {'sape': {'value': 22}, 'jack': 4098, 'guido': 4127} prettyjson(dic, depth=1, max_length=10, sort=False) 2/ json string json_str = '{"glossary": {"empty array": [], "empty object": {}, "string": "example glossary", "null field": null, "object": {"GlossList": {"GlossEntry": {"GlossDef": {"GlossSeeAlso": ["GML", "XML"], "para": "A meta-markup language, used to create markup languages such as DocBook."}, "GlossSee": "markup", "Acronym": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Abbrev": "ISO 8879:1986", "SortAs": "SGML", "ID": "SGML"}}, "title": "S"}, "number": 2, "undefined field": "undefined", "boolean": false, "array": [3, 5]}}' prettyjson(json_str, depth=6, max_length=10, max_height=500)
dic = {'sape': {'value': 22}, 'jack': 4098, 'guido': 4127}
prettyjson(dic, depth=1, max_length=10, sort=False)
json_str = '{"glossary": {"empty array": [], "empty object": {}, "string": "example glossary", "null field": null, "object": {"GlossList": {"GlossEntry": {"GlossDef": {"GlossSeeAlso": ["GML", "XML"], "para": "A meta-markup language, used to create markup languages such as DocBook."}, "GlossSee": "markup", "Acronym": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Abbrev": "ISO 8879:1986", "SortAs": "SGML", "ID": "SGML"}}, "title": "S"}, "number": 2, "undefined field": "undefined", "boolean": false, "array": [3, 5]}}'
prettyjson(json_str, depth=6, max_length=10, max_height=500)
same_json_str = """
{
"glossary": {
"string": "example glossary",
"number": 2,
"boolean": false,
"null field": null,
"undefined field": "undefined",
"empty array": [],
"empty object": {},
"array": [ 3, 5 ],
"object": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
"""
prettyjson(json.loads(same_json_str), depth=6, max_length=10, max_height=500)