{"id":21283448,"url":"https://github.com/jg-rp/python-jsonpath-rfc9535","last_synced_at":"2025-07-11T11:30:56.673Z","repository":{"id":227649817,"uuid":"771612439","full_name":"jg-rp/python-jsonpath-rfc9535","owner":"jg-rp","description":"RFC 9535 JSONPath: Query Expressions for JSON in Python","archived":false,"fork":false,"pushed_at":"2024-09-24T18:48:49.000Z","size":120,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-05T08:17:46.742Z","etag":null,"topics":["json","jsonpath","jsonpath-library","jsonpath-parser","jsonpath-query","jsonpath-syntax","python","python3"],"latest_commit_sha":null,"homepage":"","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/jg-rp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"jg-rp"}},"created_at":"2024-03-13T16:09:35.000Z","updated_at":"2024-09-24T17:33:27.000Z","dependencies_parsed_at":"2024-05-20T07:48:22.135Z","dependency_job_id":"c8f2927b-66cd-4b29-a1ed-a71aa71a2716","html_url":"https://github.com/jg-rp/python-jsonpath-rfc9535","commit_stats":null,"previous_names":["jg-rp/python-jsonpath-rfc9535"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jg-rp%2Fpython-jsonpath-rfc9535","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jg-rp%2Fpython-jsonpath-rfc9535/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jg-rp%2Fpython-jsonpath-rfc9535/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jg-rp%2Fpython-jsonpath-rfc9535/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jg-rp","download_url":"https://codeload.github.com/jg-rp/python-jsonpath-rfc9535/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225715889,"owners_count":17512909,"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","jsonpath","jsonpath-library","jsonpath-parser","jsonpath-query","jsonpath-syntax","python","python3"],"created_at":"2024-11-21T11:08:35.250Z","updated_at":"2024-11-21T11:08:35.695Z","avatar_url":"https://github.com/jg-rp.png","language":"Python","readme":"\u003ch1 align=\"center\"\u003eRFC 9535 JSONPath: Query Expressions for JSON in Python\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\nWe follow \u003ca href=\"https://datatracker.ietf.org/doc/html/rfc9535\"\u003eRFC 9535\u003c/a\u003e strictly and test against the \u003ca href=\"https://github.com/jsonpath-standard/jsonpath-compliance-test-suite\"\u003eJSONPath Compliance Test Suite\u003c/a\u003e.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/jg-rp/python-jsonpath-rfc9535/blob/main/LICENSE.txt\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/l/jsonpath-rfc9535.svg?style=flat-square\" alt=\"License\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/jg-rp/python-jsonpath-rfc9535/actions\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/jg-rp/python-jsonpath-rfc9535/tests.yaml?branch=main\u0026label=tests\u0026style=flat-square\" alt=\"Tests\"\u003e\n  \u003c/a\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://pypi.org/project/jsonpath-rfc9535\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/v/jsonpath-rfc9535.svg?style=flat-square\" alt=\"PyPi - Version\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://pypi.org/project/jsonpath-rfc9535\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/pyversions/jsonpath-rfc9535.svg?style=flat-square\" alt=\"Python versions\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n**Table of Contents**\n\n- [Install](#install)\n- [Example](#example)\n- [Links](#links)\n- [Related projects](#related-projects)\n- [API](#api)\n- [License](#license)\n\n## Install\n\nInstall Python JSONPath RFC 9535 using [pip](https://pip.pypa.io/en/stable/getting-started/):\n\n```\npip install jsonpath-rfc9535\n```\n\nOr [Pipenv](https://pipenv.pypa.io/en/latest/):\n\n```\npipenv install -u jsonpath-rfc9535\n```\n\n## Example\n\n```python\nimport jsonpath_rfc9535 as jsonpath\n\ndata = {\n    \"users\": [\n        {\"name\": \"Sue\", \"score\": 100},\n        {\"name\": \"Sally\", \"score\": 84, \"admin\": False},\n        {\"name\": \"John\", \"score\": 86, \"admin\": True},\n        {\"name\": \"Jane\", \"score\": 55},\n    ],\n    \"moderator\": \"John\",\n}\n\nfor node in jsonpath.find(\"$.users[?@.score \u003e 85]\", data):\n    print(node.value)\n\n# {'name': 'Sue', 'score': 100}\n# {'name': 'John', 'score': 86, 'admin': True}\n```\n\nOr, reading JSON data from a file:\n\n```python\nimport json\nimport jsonpath_rfc9535 as jsonpath\n\nwith open(\"/path/to/some.json\", encoding=\"utf-8\") as fd:\n    data = json.load(fd)\n\nnodes = jsonpath.find(\"$.some.query\", data)\nvalues = nodes.values()\n# ...\n```\n\nYou could read data from a YAML formatted file too. If you have [PyYaml](https://pyyaml.org/wiki/PyYAML) installed:\n\n```python\nimport jsonpath_rfc9535 as jsonpath\nimport yaml\n\nwith open(\"some.yaml\") as fd:\n    data = yaml.safe_load(fd)\n\nproducts = jsonpath.find(\"$..products.*\", data).values()\n# ...\n```\n\n## Links\n\n- Change log: https://github.com/jg-rp/python-jsonpath-rfc9535/blob/main/CHANGELOG.md\n- PyPi: https://pypi.org/project/jsonpath-rfc9535\n- Source code: https://github.com/jg-rp/python-jsonpath-rfc9535\n- Issue tracker: https://github.com/jg-rp/python-jsonpath-rfc9535/issues\n\n## Related projects\n\n- [Python JSONPath](https://github.com/jg-rp/python-jsonpath) - Another Python package implementing JSONPath, but with additional features and customization options.\n- [JSON P3](https://github.com/jg-rp/json-p3) - RFC 9535 implemented in TypeScript.\n\n## API\n\n### find\n\n`find(query: str, value: JSONValue) -\u003e JSONPathNodeList`\n\nApply JSONPath expression _query_ to _value_. _value_ should arbitrary, possible nested, Python dictionaries, lists, strings, integers, floats, Booleans or `None`, as you would get from [`json.load()`](https://docs.python.org/3/library/json.html#json.load).\n\nA list of `JSONPathNode` instances is returned, one node for each value matched by _query_. The returned list will be empty if there were no matches.\n\nEach `JSONPathNode` has:\n\n- a `value` property, which is the JSON-like value associated with the node.\n- a `location` property, which is a tuple of property names and array/list indexes that were required to reach the node's value in the target JSON document.\n- a `path()` method, which returns the normalized path to the node in the target JSON document.\n\n```python\nimport jsonpath_rfc9535 as jsonpath\n\nvalue = {\n    \"users\": [\n        {\"name\": \"Sue\", \"score\": 100},\n        {\"name\": \"John\", \"score\": 86, \"admin\": True},\n        {\"name\": \"Sally\", \"score\": 84, \"admin\": False},\n        {\"name\": \"Jane\", \"score\": 55},\n    ],\n    \"moderator\": \"John\",\n}\n\nfor node in jsonpath.find(\"$.users[?@.score \u003e 85]\", value):\n    print(f\"{node.value} at '{node.path()}'\")\n\n# {'name': 'Sue', 'score': 100} at '$['users'][0]'\n# {'name': 'John', 'score': 86, 'admin': True} at '$['users'][1]'\n```\n\n`JSONPathNodeList` is a subclass of `list` with some helper methods.\n\n- `values()` returns a list of values, one for each node.\n- `items()` returns a list of `(normalized path, value)` tuples.\n\n### find_one\n\n`find_one(query: str, value: JSONValue) -\u003e Optional[JSONPathNode]`\n\n`find_one()` accepts the same arguments as [`find()`](#findquery-value), but returns the first available `JSONPathNode`, or `None` if there were no matches.\n\n`find_one()` is equivalent to:\n\n```python\ndef find_one(query, value):\n    try:\n        return next(iter(jsonpath.finditer(query, value)))\n    except StopIteration:\n        return None\n```\n\n### finditer\n\n`finditer(query: str, value: JSONValue) -\u003e Iterable[JSONPathNode]`\n\n`finditer()` accepts the same arguments as [`find()`](#findquery-value), but returns an iterator over `JSONPathNode` instances rather than a list. This could be useful if you're expecting a large number of results that you don't want to load into memory all at once.\n\n### compile\n\n`compile(query: str) -\u003e JSONPathQuery`\n\n`find(query, value)` is a convenience function for `JSONPathEnvironment().compile(query).apply(value)`. Use `compile(query)` to obtain a `JSONPathQuery` instance which can be applied to difference JSON-like values repeatedly.\n\n```python\nimport jsonpath_rfc9535 as jsonpath\n\nvalue = {\n    \"users\": [\n        {\"name\": \"Sue\", \"score\": 100},\n        {\"name\": \"John\", \"score\": 86, \"admin\": True},\n        {\"name\": \"Sally\", \"score\": 84, \"admin\": False},\n        {\"name\": \"Jane\", \"score\": 55},\n    ],\n    \"moderator\": \"John\",\n}\n\nquery = jsonpath.compile(\"$.users[?@.score \u003e 85]\")\n\nfor node in query.apply(value):\n    print(f\"{node.value} at '{node.path()}'\")\n\n# {'name': 'Sue', 'score': 100} at '$['users'][0]'\n# {'name': 'John', 'score': 86, 'admin': True} at '$['users'][1]'\n```\n\nA `JSONPathQuery` has a `finditer(value)` method too, and `find(value)` is an alias for `apply(value)`.\n\n## License\n\n`python-jsonpath-rfc9535` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n","funding_links":["https://github.com/sponsors/jg-rp"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjg-rp%2Fpython-jsonpath-rfc9535","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjg-rp%2Fpython-jsonpath-rfc9535","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjg-rp%2Fpython-jsonpath-rfc9535/lists"}