{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import json\n", "\n", "from ezjson import prettyjson" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##prettyjson doc" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", " Pretty display json or dictionnary in collapsible format with indents\n", "\n", " Options are\n", " depth: Depth of the json tree structure displayed, the rest is collapsed. By default: 2.\n", " max_length: Maximum number of characters of a string displayed as preview, longer string appear collapsed. By default: 20.\n", " sort: Whether the json keys are sorted alphabetically. By default: True.\n", " max_height: Maxium height in pixels of containing div. By default: 600.\n", "\n", " Examples:\n", " 1/ Python dictionary\n", " dic = {'sape': {'value': 22}, 'jack': 4098, 'guido': 4127}\n", " prettyjson(dic, depth=1, max_length=10, sort=False)\n", "\n", " 2/ json string\n", " 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]}}'\n", " prettyjson(json_str, depth=6, max_length=10, max_height=500)\n", "\n", " \n" ] } ], "source": [ "print prettyjson.__doc__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##from Python dictionnary" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dic = {'sape': {'value': 22}, 'jack': 4098, 'guido': 4127}\n", "prettyjson(dic, depth=1, max_length=10, sort=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##from Python json string" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "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]}}'\n", "prettyjson(json_str, depth=6, max_length=10, max_height=500)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "same_json_str = \"\"\"\n", "{\n", " \"glossary\": {\n", " \"string\": \"example glossary\",\n", " \"number\": 2,\n", " \"boolean\": false,\n", " \"null field\": null,\n", " \"undefined field\": \"undefined\",\n", " \"empty array\": [],\n", " \"empty object\": {},\n", " \"array\": [ 3, 5 ],\n", " \"object\": {\n", " \"title\": \"S\",\n", " \"GlossList\": {\n", " \"GlossEntry\": {\n", " \"ID\": \"SGML\",\n", " \"SortAs\": \"SGML\",\n", " \"GlossTerm\": \"Standard Generalized Markup Language\",\n", " \"Acronym\": \"SGML\",\n", " \"Abbrev\": \"ISO 8879:1986\",\n", " \"GlossDef\": {\n", " \"para\": \"A meta-markup language, used to create markup languages such as DocBook.\",\n", " \"GlossSeeAlso\": [\"GML\", \"XML\"]\n", " },\n", " \"GlossSee\": \"markup\"\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\"\"\"\n", "\n", "prettyjson(json.loads(same_json_str), depth=6, max_length=10, max_height=500)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }