{ "info": { "author": "eHealth Africa", "author_email": "aether@ehealthafrica.org", "bugtrack_url": null, "classifiers": [], "description": "# jsonpath-extensions\n\n\nProvides new [Extensions to the jsonpath_ng python library](https://github.com/h2non/jsonpath-ng#extensions) to provide commonly requested functions. The context for these functions is always the value provided from the resolution of the provided jsonpath. The functions will all handle lists or single values as inputs unless explicitly marked. If you're confused about a function's intended, behavior take a look at [the tests](https://github.com/eHealthAfrica/jsonpath-extensions/blob/master/test/test.py).\n\n## Usage\n\n```python\nfrom eha_jsonpath import parse\n# The following is pseudocode, don't copy it.\nobj = {'my': 'object'}\npath = '$.some.jsonpath.`fn(arg1, arg2)`'\nmatches = parse(path).find(obj)\n```\n\n## New Extensions\n\n### Cast\n\nAttempts to apply a cast to the result of a jsonpath expression. \nWill operate invidiually on array items in the case the path resolves to an array.\n\n_usage:_ ```$.my.path.`cast({castType})` ```\n\nsupported castTypes and _behavior:_\n```python\n\nCASTS = {\n 'int': lambda x: _cast_int(x), # see below\n 'boolean': lambda x: bool(x),\n 'string': lambda x: str(x),\n 'float': lambda x: float(x),\n 'json': lambda x: json.loads(x), # standard json library\n 'none': lambda x: x,\n 'null': lambda x: None\n}\n\n\ndef _cast_int(obj):\n # fixes issues when trying to cast a float str -> int\n # int('1.09') throws ValueError\n try:\n return int(obj)\n except ValueError:\n return int(float(obj))\n```\n\n### Split List\n\nTakes a string at a given jsonpath and attempts to split it into an array of given `delimiter` and casts the array items to a specific `castType`. See valid casts in Cast section.\n\nThe resolved path _must_ be a string. *Will not* operate invidiually on array items in the case the path resolves to an array.\n\n_usage:_ ```$.my.path.`splitlist({delimiter}, {castType})` ```\n\n\n\n### Match\n\nChecks the value found at a jsonpath against a provided `match_term`. If the value is not found, returns the `null_value`. Will operate invidiually on array items in the case the path resolves to an array.\n\n\n_usage:_ ```$.my.path.`match({match_term}, {null_value})` ```\n\n*_White space after commas is required!_*\n\n_behavior:_\n\n```python\nresult = (value == match_term) if value != None else null_value\n``` \n\n### Not Match\n\n\nProvides the inverse of Match. Checks the value found at a jsonpath against a provided `match_term`. If the value is not found, returns the `null_value`. Will operate invidiually on array items in the case the path resolves to an array.\n\n_usage:_ ```$.my.path.`notmatch({match_term}, {null_value})` ```\n\n*_White space after commas is required!_*\n\n_behavior:_\n\n```python\nresult = (value != match_term) if value != None else null_value\n``` \n\n\n### Parse Datetime\n\nAttempts to parse the iso formatted datetime from a string found at a given jsonpath. Then returns a part or the whole of the parsed datetime as specified by a python array slice. Will operate invidiually on array items in the case the path resolves to an array. The `strptime_str` format is taken from the [python strptime behavior](https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior). The array slice notation used in `return_slice` is uses the standard [slice operator](https://docs.python.org/3/library/functions.html?highlight=slice#slice), with semi-colon delimited arguments like:\n\n```python\ndef args_to_slice(cls, return_slice, obj):\n defaults = [0, None, None]\n parts = []\n for x, i in enumerate(return_slice.split(':')):\n try:\n parts.append(int(i))\n except ValueError:\n parts.append(defaults[x])\n return obj[slice(*parts)]\n```\n\n_usage:_ ```$.my.path.`datetime({strptime_str}, {return_slice})` ```\n\n*_White space after commas is required!_*\n\n\n### Hash\n\nReturns a 128bit, hex formatted MD5 hash of the value of a resolved jsonpath added to a provided `salt`. This is useful for generating a UUID compatable value from a piece of source information along with some unique salt. This allows for a non-UUID foreign key to be reliably converted to the same UUID compatable value every time. Will operate invidiually on array items in the case the path resolves to an array.\n\n_usage:_ ```$.my.path.`hash({salt})` ```\n\n\n### Template\n\nWill substitue the value found at a resolved jsonpath into a formatted string with a singe replacement place holder. Will operate invidiually on array items in the case the path resolves to an array.\n\n_usage:_ \nUsing of format resembling: ` my name is {} `\n\n```$.my.path.`template({template_format)` ```\n\n\n### Value Replace\n\nReplaces resolved values matching `match_value` with `replacement_value`. Will operate invidiually on array items in the case the path resolves to an array.\n\n_usage:_ ```$.my.path.`valuereplace({match_value}, {replacement_value})` ```\n\n*_White space after commas is required!_*\n\n_behavior:_ \n```python\nreplacement_value if (match_value == value) else value\n```\n\n\n### Dictionary Replace\n\nReplaces resolved values matching a key in a passed dictionary with the appropriate value from the same dictionary. Will operate invidiually on array items in the case the path resolves to an array. The dictionary argument should be a stringified python dictionary.\n\n_usage:_ ```$.my.path.`dictionaryreplace({stringified_python_dictionary})` ```\nresult is: path value replaces with value of matching key in dictionary\n\n_behavior:_\n```python\nreturn passed_dict.get(value, None)\n\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/eHealthAfrica/jsonpath-extensions/", "keywords": "", "license": "Apache2 License", "maintainer": "", "maintainer_email": "", "name": "eha-jsonpath", "package_url": "https://pypi.org/project/eha-jsonpath/", "platform": "", "project_url": "https://pypi.org/project/eha-jsonpath/", "project_urls": { "Homepage": "https://github.com/eHealthAfrica/jsonpath-extensions/" }, "release_url": "https://pypi.org/project/eha-jsonpath/0.5.1/", "requires_dist": [ "jsonpath-ng" ], "requires_python": "", "summary": "jsonpath_ng with extended functionality", "version": "0.5.1" }, "last_serial": 5516292, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "1ae55d1df59adb7c1633fde157fe296c", "sha256": "804eeb47d6459e064183995d4fa00ec0d8a766458831d7768387c9648e0ba99a" }, "downloads": -1, "filename": "eha_jsonpath-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "1ae55d1df59adb7c1633fde157fe296c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7253, "upload_time": "2019-05-13T08:18:32", "url": "https://files.pythonhosted.org/packages/76/a5/8bd35e008bba94856c8197035433edddda8cacf95a2d8e8f89a2948ab3b9/eha_jsonpath-0.0.1-py3-none-any.whl" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "136f6d66ae78552f96faa50e80c3c43b", "sha256": "6e1aa58c3946bd2246659f0ac33f6bdf1d1ebc7f3330f107e4d56763c8d41b78" }, "downloads": -1, "filename": "eha_jsonpath-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "136f6d66ae78552f96faa50e80c3c43b", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7301, "upload_time": "2019-05-13T08:23:43", "url": "https://files.pythonhosted.org/packages/0a/06/201f3f716d473221c79207d14aaa0b69c21c6ce9abc0d34e977925417ecd/eha_jsonpath-0.1.1-py2.py3-none-any.whl" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "e19e8bf81f7ea99e0f3ddcb810a935c6", "sha256": "1b0ec4c74aff1958bace874722db28577edf0eb375613ec0fbb181ac9d43ff6f" }, "downloads": -1, "filename": "eha_jsonpath-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e19e8bf81f7ea99e0f3ddcb810a935c6", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7465, "upload_time": "2019-05-13T09:23:54", "url": "https://files.pythonhosted.org/packages/40/74/87ffd0758f63eeb679d48fc86f587127b429a8c953e59a3fc2dce6f6717d/eha_jsonpath-0.2.0-py2.py3-none-any.whl" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "ed06d7f81d1736a7a6198eee85d33381", "sha256": "8acd753deb1edce5bbc7d5ba77c9b947b552b76801c95a6db64f0c35972c5cef" }, "downloads": -1, "filename": "eha_jsonpath-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ed06d7f81d1736a7a6198eee85d33381", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7571, "upload_time": "2019-05-13T11:16:56", "url": "https://files.pythonhosted.org/packages/e0/bc/80916b5dbedd92740228589ac34d43800d972e12c9e1bd821b3f5b743183/eha_jsonpath-0.3.0-py2.py3-none-any.whl" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "ddbcd0d1a7c5f3d0c34c8d9bbbf0297d", "sha256": "2d4bf0b74f4229206b4ebb82c8d248a97dfd72b56ab51f163b0766cc9d20eb88" }, "downloads": -1, "filename": "eha_jsonpath-0.4.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ddbcd0d1a7c5f3d0c34c8d9bbbf0297d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7655, "upload_time": "2019-05-13T14:30:04", "url": "https://files.pythonhosted.org/packages/03/21/7e895a93c79fe1c994d8ffda23477e8d6e4677ad00cec87fa55eb68e285a/eha_jsonpath-0.4.0-py2.py3-none-any.whl" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "c2940d0fafecb38bd17d187984596e8d", "sha256": "ef0db4ef93a9302a759a7de02b3a5348aed7a56626095bf0719edc5b25b405a1" }, "downloads": -1, "filename": "eha_jsonpath-0.5.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c2940d0fafecb38bd17d187984596e8d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9720, "upload_time": "2019-05-20T13:24:03", "url": "https://files.pythonhosted.org/packages/ef/5f/6a8f24e26bddc2f552538a215a0a434652a667045464092369c8f8f93c50/eha_jsonpath-0.5.0-py2.py3-none-any.whl" } ], "0.5.1": [ { "comment_text": "", "digests": { "md5": "d2849ae8df380cff5740df563e0b1d4e", "sha256": "1d356b89c4d21a1dc581634f529ea0ecaf4e324e0a5f8e3e652d7c2048bfc35d" }, "downloads": -1, "filename": "eha_jsonpath-0.5.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d2849ae8df380cff5740df563e0b1d4e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9728, "upload_time": "2019-07-11T08:48:51", "url": "https://files.pythonhosted.org/packages/0f/44/eee5a7da478b276f6f1d9f6e70ecdc06af418db2ffd590369142a0d5f932/eha_jsonpath-0.5.1-py2.py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d2849ae8df380cff5740df563e0b1d4e", "sha256": "1d356b89c4d21a1dc581634f529ea0ecaf4e324e0a5f8e3e652d7c2048bfc35d" }, "downloads": -1, "filename": "eha_jsonpath-0.5.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d2849ae8df380cff5740df563e0b1d4e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9728, "upload_time": "2019-07-11T08:48:51", "url": "https://files.pythonhosted.org/packages/0f/44/eee5a7da478b276f6f1d9f6e70ecdc06af418db2ffd590369142a0d5f932/eha_jsonpath-0.5.1-py2.py3-none-any.whl" } ] }