{"id":17654368,"url":"https://github.com/chrisjsewell/jsonextended","last_synced_at":"2025-10-19T03:57:47.691Z","repository":{"id":60722480,"uuid":"93059012","full_name":"chrisjsewell/jsonextended","owner":"chrisjsewell","description":"Extending the python json package functionality","archived":false,"fork":false,"pushed_at":"2019-06-18T03:00:33.000Z","size":1046,"stargazers_count":7,"open_issues_count":13,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T09:15:00.580Z","etag":null,"topics":["json","physical-quantities","python-json"],"latest_commit_sha":null,"homepage":"https://jsonextended.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrisjsewell.png","metadata":{"files":{"readme":"README.ipynb","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-01T13:16:43.000Z","updated_at":"2023-08-12T04:45:35.000Z","dependencies_parsed_at":"2022-10-03T21:01:39.766Z","dependency_job_id":null,"html_url":"https://github.com/chrisjsewell/jsonextended","commit_stats":null,"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisjsewell%2Fjsonextended","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisjsewell%2Fjsonextended/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisjsewell%2Fjsonextended/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisjsewell%2Fjsonextended/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisjsewell","download_url":"https://codeload.github.com/chrisjsewell/jsonextended/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252847524,"owners_count":21813458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","physical-quantities","python-json"],"created_at":"2024-10-23T12:14:00.161Z","updated_at":"2025-10-19T03:57:42.646Z","avatar_url":"https://github.com/chrisjsewell.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"{\n \"cells\": [\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"[![Build Status](https://travis-ci.org/chrisjsewell/jsonextended.svg?branch=master)](https://travis-ci.org/chrisjsewell/jsonextended)\\n\",\n    \"[![Coverage Status](https://coveralls.io/repos/github/chrisjsewell/jsonextended/badge.svg?branch=master)](https://coveralls.io/github/chrisjsewell/jsonextended?branch=master)\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"# JSON Extended\\n\",\n    \"\\n\",\n    \"A module to extend the python json package functionality:\\n\",\n    \"\\n\",\n    \"- Treat a directory structure like a nested dictionary:\\n\",\n    \"\\n\",\n    \"   - **lightweight plugin system**: define bespoke classes for **parsing** different file extensions and **encoding/decoding** objects\\n\",\n    \"   \\n\",\n    \"   - **lazy loading**: read files only when they are indexed into \\n\",\n    \"   \\n\",\n    \"   - **tab completion**: index as tabs for quick exploration of directory\\n\",\n    \"   \\n\",\n    \"-  Manipulation of nested dictionaries:\\n\",\n    \"\\n\",\n    \"   -  enhanced pretty printer\\n\",\n    \"   \\n\",\n    \"   -  Javascript rendered, expandable tree in the Jupyter Notebook\\n\",\n    \"   \\n\",\n    \"   -  functions including; filter, merge, flatten, unflatten, diff\\n\",\n    \"   \\n\",\n    \"   -  output to directory structure (of n folder levels)\\n\",\n    \"\\n\",\n    \"-  On-disk indexing option for large json files (using the ijson package)\\n\",\n    \"\\n\",\n    \"-  Units schema concept to apply and convert physical units (using the\\n\",\n    \"   pint package)\\n\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Basic Example\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {\n    \"collapsed\": true\n   },\n   \"outputs\": [],\n   \"source\": [\n    \"from jsonextended import edict, plugins, example_mockpaths\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Take a directory structure, potentially containing multiple file types:  \"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 2,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"\\u001b[32mFolder\\u001b[0m(\\\"dir1\\\") \\n\",\n      \"   \\u001b[34mFile\\u001b[0m(\\\"file1.json\\\") Contents:\\n\",\n      \"    {\\\"key2\\\": {\\\"key3\\\": 4, \\\"key4\\\": 5}, \\\"key1\\\": [1, 2, 3]}\\n\",\n      \"   \\u001b[32mFolder\\u001b[0m(\\\"subdir1\\\") \\n\",\n      \"     \\u001b[34mFile\\u001b[0m(\\\"file1.csv\\\") Contents:\\n\",\n      \"       # a csv file\\n\",\n      \"      header1,header2,header3\\n\",\n      \"      val1,val2,val3\\n\",\n      \"      val4,val5,val6\\n\",\n      \"      val7,val8,val9\\n\",\n      \"     \\u001b[34mFile\\u001b[0m(\\\"file1.literal.csv\\\") Contents:\\n\",\n      \"       # a csv file with numbers\\n\",\n      \"      header1,header2,header3\\n\",\n      \"      1,1.1,string1\\n\",\n      \"      2,2.2,string2\\n\",\n      \"      3,3.3,string3\\n\",\n      \"   \\u001b[32mFolder\\u001b[0m(\\\"subdir2\\\") \\n\",\n      \"     \\u001b[32mFolder\\u001b[0m(\\\"subsubdir21\\\") \\n\",\n      \"       \\u001b[34mFile\\u001b[0m(\\\"file1.keypair\\\") Contents:\\n\",\n      \"         # a key-pair file\\n\",\n      \"        key1 val1\\n\",\n      \"        key2 val2\\n\",\n      \"        key3 val3\\n\",\n      \"        key4 val4\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"datadir = example_mockpaths.directory1\\n\",\n    \"print(datadir.to_string(indentlvl=3,file_content=True,color=True))\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Plugins can be defined for parsing each file type (see [Creating Plugins](#creating-and-loading-plugins) section):\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 3,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{'csv.basic': 'read *.csv delimited file with headers to {header:[column_values]}',\\n\",\n       \" 'csv.literal': 'read *.literal.csv delimited files with headers to {header:column_values}',\\n\",\n       \" 'json.basic': 'read *.json files using json.load',\\n\",\n       \" 'keypair': \\\"read *.keypair, where each line should be; '\u003ckey\u003e \u003cpair\u003e'\\\"}\"\n      ]\n     },\n     \"execution_count\": 3,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"plugins.load_builtin_plugins('parsers')\\n\",\n    \"plugins.view_plugins('parsers')\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"LazyLoad then takes a path name, path-like object or dict-like object, which will lazily load each file with a compatible plugin.\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 4,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{file1.json:..,subdir1:..,subdir2:..}\"\n      ]\n     },\n     \"execution_count\": 4,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"lazy = edict.LazyLoad(datadir)\\n\",\n    \"lazy\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Lazyload can then be treated like a dictionary, or indexed by tab completion:\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 5,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"['subdir1', 'subdir2', 'file1.json']\"\n      ]\n     },\n     \"execution_count\": 5,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"list(lazy.keys())\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 6,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"[1, 2, 3]\"\n      ]\n     },\n     \"execution_count\": 6,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"lazy[['file1.json','key1']]\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 7,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"[1.1, 2.2, 3.3]\"\n      ]\n     },\n     \"execution_count\": 7,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"lazy.subdir1.file1_literal_csv.header2\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"For pretty printing of the dictionary:\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 9,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"\\u001b[32mfile1.json\\u001b[0m: \\n\",\n      \"  \\u001b[32mkey1\\u001b[0m: [1, 2, 3]\\n\",\n      \"  \\u001b[32mkey2\\u001b[0m: {...}\\n\",\n      \"\\u001b[32msubdir1\\u001b[0m: \\n\",\n      \"  \\u001b[32mfile1.csv\\u001b[0m: {...}\\n\",\n      \"  \\u001b[32mfile1.literal.csv\\u001b[0m: {...}\\n\",\n      \"\\u001b[32msubdir2\\u001b[0m: \\n\",\n      \"  \\u001b[32msubsubdir21\\u001b[0m: {...}\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"edict.pprint(lazy,depth=2,keycolor='green')\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Numerous functions exist to manipulate the nested dictionary:\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 9,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{('file1.csv', 'header1'): ['val1', 'val4', 'val7'],\\n\",\n       \" ('file1.csv', 'header2'): ['val2', 'val5', 'val8'],\\n\",\n       \" ('file1.csv', 'header3'): ['val3', 'val6', 'val9'],\\n\",\n       \" ('file1.literal.csv', 'header1'): [1, 2, 3],\\n\",\n       \" ('file1.literal.csv', 'header2'): [1.1, 2.2, 3.3],\\n\",\n       \" ('file1.literal.csv', 'header3'): ['string1', 'string2', 'string3']}\"\n      ]\n     },\n     \"execution_count\": 9,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"edict.flatten(lazy.subdir1)\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"LazyLoad parses the `plugins.decode` function to parser plugin's `read_file` method (keyword 'object_hook'). Therefore, bespoke decoder plugins can be set up for specific dictionary key signatures:  \"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 10,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"File(\\\"file2.json\\\") Contents:\\n\",\n      \"{\\\"key1\\\":{\\\"_python_set_\\\": [1, 2, 3]},\\\"key2\\\":{\\\"_numpy_ndarray_\\\": {\\\"dtype\\\": \\\"int64\\\", \\\"value\\\": [1, 2, 3]}}}\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"print(example_mockpaths.jsonfile2.to_string())\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 11,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{u'key1': {u'_python_set_': [1, 2, 3]},\\n\",\n       \" u'key2': {u'_numpy_ndarray_': {u'dtype': u'int64', u'value': [1, 2, 3]}}}\"\n      ]\n     },\n     \"execution_count\": 11,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"edict.LazyLoad(example_mockpaths.jsonfile2).to_dict()\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 12,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{'decimal.Decimal': 'encode/decode Decimal type',\\n\",\n       \" 'numpy.ndarray': 'encode/decode numpy.ndarray',\\n\",\n       \" 'pint.Quantity': 'encode/decode pint.Quantity object',\\n\",\n       \" 'python.set': 'decode/encode python set'}\"\n      ]\n     },\n     \"execution_count\": 12,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"plugins.load_builtin_plugins('decoders')\\n\",\n    \"plugins.view_plugins('decoders')\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 13,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{u'key1': {1, 2, 3}, u'key2': array([1, 2, 3])}\"\n      ]\n     },\n     \"execution_count\": 13,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"dct = edict.LazyLoad(example_mockpaths.jsonfile2).to_dict()\\n\",\n    \"dct\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"This process can be reversed, using encoder plugins: \"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 14,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{'decimal.Decimal': 'encode/decode Decimal type',\\n\",\n       \" 'numpy.ndarray': 'encode/decode numpy.ndarray',\\n\",\n       \" 'pint.Quantity': 'encode/decode pint.Quantity object',\\n\",\n       \" 'python.set': 'decode/encode python set'}\"\n      ]\n     },\n     \"execution_count\": 14,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"plugins.load_builtin_plugins('encoders')\\n\",\n    \"plugins.view_plugins('encoders')\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 15,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"'{\\\"key2\\\": {\\\"_numpy_ndarray_\\\": {\\\"dtype\\\": \\\"int64\\\", \\\"value\\\": [1, 2, 3]}}, \\\"key1\\\": {\\\"_python_set_\\\": [1, 2, 3]}}'\"\n      ]\n     },\n     \"execution_count\": 15,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"import json\\n\",\n    \"json.dumps(dct,default=plugins.encode)\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Installation\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"    pip install jsonextended\\n\",\n    \"\\n\",\n    \"jsonextended has no import dependancies, on Python 3.x and only `pathlib2` on 2.7 but,\\n\",\n    \"for full functionallity, it is advised to install the following packages:\\n\",\n    \"\\n\",\n    \"    conda install -c conda-forge ijson numpy pint \\n\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Creating and Loading Plugins\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 16,\n   \"metadata\": {\n    \"collapsed\": true\n   },\n   \"outputs\": [],\n   \"source\": [\n    \"from jsonextended import plugins, utils\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Plugins are recognised as classes with a minimal set of attributes matching the plugin category interface:\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 17,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{'decoders': ['plugin_name', 'plugin_descript', 'dict_signature'],\\n\",\n       \" 'encoders': ['plugin_name', 'plugin_descript', 'objclass'],\\n\",\n       \" 'parsers': ['plugin_name', 'plugin_descript', 'file_regex', 'read_file']}\"\n      ]\n     },\n     \"execution_count\": 17,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"plugins.view_interfaces()\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 18,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{'decoders': {}, 'encoders': {}, 'parsers': {}}\"\n      ]\n     },\n     \"execution_count\": 18,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"plugins.unload_all_plugins()\\n\",\n    \"plugins.view_plugins()\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"For example, a simple parser plugin would be:\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 19,\n   \"metadata\": {\n    \"collapsed\": true\n   },\n   \"outputs\": [],\n   \"source\": [\n    \"class ParserPlugin(object):\\n\",\n    \"    plugin_name = 'example'\\n\",\n    \"    plugin_descript = 'a parser for *.example files, that outputs (line_number:line)'\\n\",\n    \"    file_regex = '*.example'\\n\",\n    \"    def read_file(self, file_obj, **kwargs):\\n\",\n    \"        out_dict = {}\\n\",\n    \"        for i, line in enumerate(file_obj):\\n\",\n    \"            out_dict[i] = line.strip()\\n\",\n    \"        return out_dict\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Plugins can be loaded as a class:\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 20,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{'decoders': {},\\n\",\n       \" 'encoders': {},\\n\",\n       \" 'parsers': {'example': 'a parser for *.example files, that outputs (line_number:line)'}}\"\n      ]\n     },\n     \"execution_count\": 20,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"plugins.load_plugin_classes([ParserPlugin],'parsers')\\n\",\n    \"plugins.view_plugins()\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Or by directory (loading all .py files):\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 21,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"{'decoders': {},\\n\",\n       \" 'encoders': {},\\n\",\n       \" 'parsers': {'example': 'a parser for *.example files, that outputs (line_number:line)',\\n\",\n       \"  'example.other': 'a parser for *.example.other files, that outputs (line_number:line)'}}\"\n      ]\n     },\n     \"execution_count\": 21,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"fobj = utils.MockPath('example.py',is_file=True,content=\\\"\\\"\\\"\\n\",\n    \"class ParserPlugin(object):\\n\",\n    \"    plugin_name = 'example.other'\\n\",\n    \"    plugin_descript = 'a parser for *.example.other files, that outputs (line_number:line)'\\n\",\n    \"    file_regex = '*.example.other'\\n\",\n    \"    def read_file(self, file_obj, **kwargs):\\n\",\n    \"        out_dict = {}\\n\",\n    \"        for i, line in enumerate(file_obj):\\n\",\n    \"            out_dict[i] = line.strip()\\n\",\n    \"        return out_dict\\n\",\n    \"\\\"\\\"\\\")\\n\",\n    \"dobj = utils.MockPath(structure=[fobj])\\n\",\n    \"plugins.load_plugins_dir(dobj,'parsers')\\n\",\n    \"plugins.view_plugins()\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"For a more complex example of a parser, see `jsonextended.complex_parsers`\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"### Interface details\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"- Parsers:\\n\",\n    \"\\n\",\n    \"    - *file_regex* attribute, a str denoting what files to apply it to. A file will be parsed by the longest regex it matches.\\n\",\n    \"    - *read_file* method, which takes an (open) file object and kwargs as parameters \\n\",\n    \" \\n\",\n    \"- Decoders:\\n\",\n    \"\\n\",\n    \"    - *dict_signature* attribute, a tuple denoting the keys which the dictionary must have, e.g. dict_signature=('a','b') decodes {'a':1,'b':2}\\n\",\n    \"    - *from_...* method(s), which takes a dict object as parameter. The `plugins.decode` function will use the method denoted by the intype parameter, e.g. if intype='json', then *from_json* will be called.\\n\",\n    \"    \\n\",\n    \"- Encoders:\\n\",\n    \"\\n\",\n    \"    - *objclass* attribute, the object class to apply the encoding to, e.g. objclass=decimal.Decimal encodes objects of that type\\n\",\n    \"    - *to_...* method(s), which takes a dict object as parameter. The `plugins.encode` function will use the method denoted by the outtype parameter, e.g. if outtype='json', then *to_json* will be called.\\n\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Extended Examples\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"For more information, all functions contain docstrings with tested examples.\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"### Data Folders JSONisation\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 22,\n   \"metadata\": {\n    \"collapsed\": true\n   },\n   \"outputs\": [],\n   \"source\": [\n    \"from jsonextended import ejson, edict, utils\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 23,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"['dir1', 'dir2', 'dir3']\"\n      ]\n     },\n     \"execution_count\": 23,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"path = utils.get_test_path()\\n\",\n    \"ejson.jkeys(path)\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 24,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"dir1: \\n\",\n      \"  dir1_1: {...}\\n\",\n      \"  file1: {...}\\n\",\n      \"  file2: {...}\\n\",\n      \"dir2: \\n\",\n      \"  file1: {...}\\n\",\n      \"dir3: \\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"jdict1 = ejson.to_dict(path)\\n\",\n    \"edict.pprint(jdict1,depth=2)\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": null,\n   \"metadata\": {\n    \"collapsed\": true\n   },\n   \"outputs\": [],\n   \"source\": [\n    \"edict.to_html(jdict1,depth=2)\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"To try the rendered JSON tree, output in the Jupyter Notebook, go to : https://chrisjsewell.github.io/\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"### Nested Dictionary Manipulation\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 26,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"initial: {...}\\n\",\n      \"meta: {...}\\n\",\n      \"optimised: {...}\\n\",\n      \"units: {...}\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"jdict2 = ejson.to_dict(path,['dir1','file1'])\\n\",\n    \"edict.pprint(jdict2,depth=1)\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 27,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"initial: \\n\",\n      \"  crystallographic: \\n\",\n      \"    volume: 924.62752781\\n\",\n      \"  primitive: \\n\",\n      \"    volume: 462.313764\\n\",\n      \"optimised: \\n\",\n      \"  crystallographic: \\n\",\n      \"    volume: 1063.98960509\\n\",\n      \"  primitive: \\n\",\n      \"    volume: 531.994803\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"filtered = edict.filter_keys(jdict2,['vol*'],use_wildcards=True)\\n\",\n    \"edict.pprint(filtered)\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 28,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"(initial, crystallographic, volume):   924.62752781\\n\",\n      \"(initial, primitive, volume):          462.313764\\n\",\n      \"(optimised, crystallographic, volume): 1063.98960509\\n\",\n      \"(optimised, primitive, volume):        531.994803\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"edict.pprint(edict.flatten(filtered))\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"### Units Schema\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 29,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"initial: \\n\",\n      \"  crystallographic: \\n\",\n      \"    volume: 924.62752781 angstrom ** 3\\n\",\n      \"  primitive: \\n\",\n      \"    volume: 462.313764 angstrom ** 3\\n\",\n      \"optimised: \\n\",\n      \"  crystallographic: \\n\",\n      \"    volume: 1063.98960509 angstrom ** 3\\n\",\n      \"  primitive: \\n\",\n      \"    volume: 531.994803 angstrom ** 3\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"from jsonextended.units import apply_unitschema, split_quantities\\n\",\n    \"withunits = apply_unitschema(filtered,{'volume':'angstrom^3'})\\n\",\n    \"edict.pprint(withunits)\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 30,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"initial: \\n\",\n      \"  crystallographic: \\n\",\n      \"    volume: 0.92462752781 nanometer ** 3\\n\",\n      \"  primitive: \\n\",\n      \"    volume: 0.462313764 nanometer ** 3\\n\",\n      \"optimised: \\n\",\n      \"  crystallographic: \\n\",\n      \"    volume: 1.06398960509 nanometer ** 3\\n\",\n      \"  primitive: \\n\",\n      \"    volume: 0.531994803 nanometer ** 3\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"newunits = apply_unitschema(withunits,{'volume':'nm^3'})\\n\",\n    \"edict.pprint(newunits)\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 31,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"initial: \\n\",\n      \"  crystallographic: \\n\",\n      \"    volume: \\n\",\n      \"      magnitude: 0.92462752781\\n\",\n      \"      units:     nanometer ** 3\\n\",\n      \"  primitive: \\n\",\n      \"    volume: \\n\",\n      \"      magnitude: 0.462313764\\n\",\n      \"      units:     nanometer ** 3\\n\",\n      \"optimised: \\n\",\n      \"  crystallographic: \\n\",\n      \"    volume: \\n\",\n      \"      magnitude: 1.06398960509\\n\",\n      \"      units:     nanometer ** 3\\n\",\n      \"  primitive: \\n\",\n      \"    volume: \\n\",\n      \"      magnitude: 0.531994803\\n\",\n      \"      units:     nanometer ** 3\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"edict.pprint(split_quantities(newunits),depth=4)\"\n   ]\n  }\n ],\n \"metadata\": {\n  \"hide_input\": false,\n  \"kernelspec\": {\n   \"display_name\": \"Python 2\",\n   \"language\": \"python\",\n   \"name\": \"python2\"\n  },\n  \"language_info\": {\n   \"codemirror_mode\": {\n    \"name\": \"ipython\",\n    \"version\": 2\n   },\n   \"file_extension\": \".py\",\n   \"mimetype\": \"text/x-python\",\n   \"name\": \"python\",\n   \"nbconvert_exporter\": \"python\",\n   \"pygments_lexer\": \"ipython2\",\n   \"version\": \"2.7.13\"\n  },\n  \"nav_menu\": {},\n  \"toc\": {\n   \"navigate_menu\": true,\n   \"number_sections\": true,\n   \"sideBar\": true,\n   \"threshold\": 4.0,\n   \"toc_cell\": false,\n   \"toc_section_display\": \"block\",\n   \"toc_window_display\": true\n  }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisjsewell%2Fjsonextended","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisjsewell%2Fjsonextended","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisjsewell%2Fjsonextended/lists"}