{"id":27165760,"url":"https://github.com/brunompena/jsonparser","last_synced_at":"2026-05-18T00:09:14.578Z","repository":{"id":285539048,"uuid":"958469362","full_name":"brunompena/jsonparser","owner":"brunompena","description":"Python module for extracting data from JSON using complex JSON paths","archived":false,"fork":false,"pushed_at":"2025-04-01T19:22:59.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-23T05:43:32.092Z","etag":null,"topics":["json","jsonpath"],"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/brunompena.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-01T08:49:58.000Z","updated_at":"2025-04-01T19:23:03.000Z","dependencies_parsed_at":"2025-04-01T10:27:03.439Z","dependency_job_id":"2a903796-34d1-497d-bf8a-63747b1d9ad0","html_url":"https://github.com/brunompena/jsonparser","commit_stats":null,"previous_names":["brunompena/jsonparser"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/brunompena/jsonparser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunompena%2Fjsonparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunompena%2Fjsonparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunompena%2Fjsonparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunompena%2Fjsonparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brunompena","download_url":"https://codeload.github.com/brunompena/jsonparser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunompena%2Fjsonparser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33160168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T22:39:12.733Z","status":"ssl_error","status_checked_at":"2026-05-17T22:39:10.741Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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"],"created_at":"2025-04-09T03:20:35.194Z","updated_at":"2026-05-18T00:09:14.565Z","avatar_url":"https://github.com/brunompena.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSONParser\n\nPython module for extracting data from JSON using complex JSON paths.\n\nThis module contains three public objects:\n\n - `JSONParser`: Used to load/save JSON objects from/to files or strings.\n - `JSONPath`: Path to one or more elements of a JSON object.\n - `JSONElement`: Combines a path with an element of a JSON object.\n\n## JSONPath syntax\n\nA JSONPath is a string used to express an element - or set of elements - of a JSON object.\n\nIt always begins with the root character - `$` - and may be followed by any number of child elements.\n\nChild elements can be expressed using the dot-notation or bracket–notation, or combination of both:\n\n`$.store.book[0].title`\u003cbr/\u003e\n`$[\"store\"][\"book\"][0][\"title\"]`\u003cbr/\u003e\n`$.store.[\"book\"].[0].title`\n\n### Path elements\n\n| Element                   | Description                                                        |\n| :------------------------ | :----------------------------------------------------------------- |\n| `$`                       | Root - must be the first element of a JSONPath.                    |\n| `.\u003cname\u003e`                 | Dot-notated child - \u003cname\u003e must match the regex [1].               |\n| `[\"\u003cname\u003e\"]`              | Bracket-notated child - \u003cname\u003e must be quoted and match regex [2]. |\n| `[\u003cindex\u003e]`               | Array index - \u003cindex\u003e must match regex [3].                        |\n| `[r\"\u003cregex\u003e\"]`            | Regex expression - \u003cregex\u003e must match regex [2].                   |\n| `.*.` or `..`             | Search - will recursively search for first match.                  |\n| `.*.*.` or `...`          | Deep search - will recursively search for all matches.             |\n\n\n[1] Simple string: `[a-zA-Z_][0-9a-zA-Z_]*`\u003cbr/\u003e\n[2] Complex string: `([^\"\\\\]|\\\\.)*`\u003cbr/\u003e\n[3] Array index: `[0-9]+|\\*?`\n\n### Examples\n\nGiven the following JSON object:\n\n```\n{\n    \"a\": 1,\n    \"b\": 2,\n    \"c\": {\n        \"a\": 3,\n        \"b\": [\n            \"abc\",\n            \"def\",\n            {\n                \"a\": 4,\n                \"b\": 5\n            }\n        ],\n        \"c\": {\n            \"a\": {\n                \"d\": 6,\n                \"e\": 7,\n                \"f\": 8\n            },\n            \"b\": {\n                \"a\": 9,\n                \"b\": 10,\n                \"c\": 11,\n                \"ab\": {\n                    \"abc\": \"xyz\"\n                }\n            }\n        }\n    }\n}\n```\n\nFind below several examples of JSONPath and the matching elements:\n\n```\nJSONPath: $..a\nElements:\n  $.a\n\nJSONPath: $..ab\nElements:\n  $.c.c.b.ab\n\nJSONPath: $...a\nElements:\n  $.a\n  $.c.a\n  $.c.b[2].a\n  $.c.c.a\n  $.c.c.b.a\n\nJSONPath: $..[r\"a.*\"]\nElements:\n  $.a\n\nJSONPath: $..[r\"a.+\"]\nElements:\n  $.c.c.b.ab\n\nJSONPath: $...[r\"a.+\"]\nElements:\n  $.c.c.b.ab\n  $.c.c.b.ab.abc\n\nJSONPath: $...[r\"[a-z]{3}\"]\nElements:\n  $.c.c.b.ab.abc\n\nJSONPath: $.c.b[2]\nElements:\n  $.c.b[2]\n\nJSONPath: $.c.b[]\nElements:\n  $.c.b[0]\n  $.c.b[1]\n  $.c.b[2]\n\nJSONPath: $.c.b[*]\nElements:\n  $.c.b[0]\n  $.c.b[1]\n  $.c.b[2]\n```\n\n## How to use the library\n\n```\nfrom JSONParser import *\n\njsonstring = '{\"a\":1,\"b\":2,\"c\":{\"a\":3,\"b\":[\"abc\",\"def\",{\"a\":4,\"b\":5}],\"c\":{\"a\":{\"d\":6,\"e\":7,\"f\":8},\"b\":{\"a\":9,\"b\":10,\"c\":11,\"ab\":{\"abc\":\"xyz\"}}}}}'\n\njson = JSONParser.loads(jsonstring)\n\nfor el in json.extract('$...[r\"[a-z]{2,}\"]'):\n    print(el.path())\n    print(el.object())\n# $.c.c.b.ab\n# {'abc': 'xyz'}\n# $.c.c.b.ab.abc\n# xyz\n\npath = JSONPath()\nprint(path)\n# $\n\npath = path + \"c\" + \"b\"\nprint(path)\n# $.c.b\n\nfor el in path.extract(json):\n    print(el.path())\n    print(el.object())\n# $.c.b\n# ['abc', 'def', {'a': 4, 'b': 5}]\n```\n\n## Module reference\n\n### JSONParser.load(filename, ...) : JSONElement\n`filename`: string with the filename containing the JSON data to load\u003cbr/\u003e\n`...`: additional arguments to be passed on to the underlying `json.load` function\u003cbr/\u003e\n\nReturns a JSONElement with the object represented by the contents of `filename` and a path of `$`.\n\n### JSONParser.loads(string, ...) : JSONElement\n`string`: string with the JSON object representation\u003cbr/\u003e\n`...`: additional arguments to be passed on to the underlying `json.loads` function\u003cbr/\u003e\n\nReturns a JSONElement with the object represented by the contents of `string` and a path of `$`.\n\n### JSONParser.dump(object, filename, ...) : None\n`object`: can be one of `JSONElement`, `dict`, `list`, `str`, `int`, `bool`\u003cbr/\u003e\n`filename`: string with the filename where to save the contents of `object`\u003cbr/\u003e\n`...`: additional arguments to be passed on to the underlying `json.dump` function\u003cbr/\u003e\n\nWrites the JSON `object` to `filename`.\n\n### JSONParser.dumps(object, ...) : str\n`object`: can be one of `JSONElement`, `dict`, `list`, `str`, `int`, `bool`\u003cbr/\u003e\n`...`: additional arguments to be passed on to the underlying `json.dumps` function\u003cbr/\u003e\n\nReturns a `str` with the representation of the JSON `object`.\n\n### JSONParser.extract(object, path) : [ JSONElement, ... ]\n`object`: can be one of `JSONElement`, `dict`, `list`, `str`, `int`, `bool`\u003cbr/\u003e\n`path`: can be one of `JSONPath`, `str`\u003cbr/\u003e\n\nReturns an array of JSONElement extracted from `object` that matched the provided `path`.\n\n### JSONParser.matches(path1, path2) : bool\n`path1`: can be one of `JSONPath`, `str`\u003cbr/\u003e\n`path2`: can be one of `JSONPath`, `str`\u003cbr/\u003e\n\nReturns `True` if the expansion of `path2` matches `path1`, and `False` otherwise.\n\n---\n\n### JSONPath.\\_\\_init\\_\\_(path=None) : JSONPath\n`path`: string with a valid path (defaults to `$`)\u003cbr/\u003e\n\nReturn a new JSONPath created from `path`.\n\n### JSONPath.\\_\\_add\\_\\_(object) : JSONPath\n`object`: can be one of `tuple`, `str`, `int`, `re.Pattern`\u003cbr/\u003e\nTuples are used to signal for search or deep search:\n - simple tuple for search: `(\"obj-abc\",)`\n - complex tuple for deep search: `((\"obj-abc\",),)`\n\nReturns a new JSONPath with the `object` representation appended to the path.\n\n### JSONPath.path() : str\n\nReturns the current path as a string representation.\n\n### JSONPath.entries(pack=True) : [ object, ... ]\n`pack`: if set to `True` then the search and deep search elements will be packed in tuples.\n\nReturns an array of objects (`str`, `int`, `re.Pattern`) representing the path elements.\u003cbr/\u003e\n\n### JSONPath.parent() : JSONPath\n\nReturns a `JSONPath` representing the parent of this path.\n\n### JSONPath.current(pack=False) : object\n`pack`: if set to `True` then the search and deep search elements will be packed in tuples.\n\nReturns the current path element.\n\n### JSONPath.extract(object) : [ JSONElement, ... ]\n`object`: can be one of `JSONElement`, `dict`, `list`, `str`, `int`, `bool`\u003cbr/\u003e\n\nReturns an array of JSONElement extracted from `object` using the current path.\n\n### JSONPath.matches(path) : bool\n`path`: can be one of `JSONPath`, `str`\u003cbr/\u003e\n\nReturns `True` if the expanded `path` matches the current path, and `False` otherwise.\n\n---\n\n### JSONElement.\\_\\_init\\_\\_(object, path=None) : JSONElement\n`object`: can be one of `JSONElement`, `dict`, `list`, `str`, `int`, `bool`\u003cbr/\u003e\n`path`: can be one of `JSONPath`, `str` (defaults `$`)\u003cbr/\u003e\n\nReturn a new JSONElement created from `object` and `path`.\n\n### JSONElement.path() : JSONPath\n\nReturns the path associated with this element.\n\n### JSONElement.object() : object\n\nReturns the JSON object associated with this element.\n\n### JSONElement.key() : object\n\nReturns the current path element.\n\n### JSONElement.value() : object\n\nReturns the current JSON element.\n\n### JSONElement.extract(path) : [ JSONElement, ... ]\n`path`: can be one of `JSONPath`, `str` (defaults `$`)\u003cbr/\u003e\n\nReturns an array of JSONElement extracted from the current object using `path`.\n\n### JSONElement.matches(path) : bool\n`path`: can be one of `JSONPath`, `str` (defaults `$`)\u003cbr/\u003e\n\nReturns `True` if the expanded `path` matches the current path, and `False` otherwise.\n\n### JSONElement.json() : str\n\nReturns the current element as a JSON string.\n\n### JSONElement.__str__() : str\n\nReturns the a textual representation of the current element (both path and json object).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunompena%2Fjsonparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrunompena%2Fjsonparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunompena%2Fjsonparser/lists"}