#!/usr/bin/env python # coding: utf-8 # In[1]: import json from ezjson import prettyjson # ##prettyjson doc # In[2]: print prettyjson.__doc__ # ##from Python dictionnary # In[3]: dic = {'sape': {'value': 22}, 'jack': 4098, 'guido': 4127} prettyjson(dic, depth=1, max_length=10, sort=False) # ##from Python json string # In[4]: 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) # In[5]: 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) # In[ ]: