{"id":17127955,"url":"https://github.com/rohanrhu/python-jsonic","last_synced_at":"2025-03-24T04:18:28.839Z","repository":{"id":65485682,"uuid":"213904718","full_name":"rohanrhu/python-jsonic","owner":"rohanrhu","description":"Python bindings for Jsonic JSON reader library.","archived":false,"fork":false,"pushed_at":"2021-12-04T17:25:42.000Z","size":87,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T03:43:53.656Z","etag":null,"topics":["json","json-parser","json-reader-library","python","python-json","zero-allocation"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pyjsonic/","language":"C","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/rohanrhu.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}},"created_at":"2019-10-09T11:51:24.000Z","updated_at":"2021-12-04T17:24:52.000Z","dependencies_parsed_at":"2023-01-25T12:55:10.680Z","dependency_job_id":null,"html_url":"https://github.com/rohanrhu/python-jsonic","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohanrhu%2Fpython-jsonic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohanrhu%2Fpython-jsonic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohanrhu%2Fpython-jsonic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohanrhu%2Fpython-jsonic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rohanrhu","download_url":"https://codeload.github.com/rohanrhu/python-jsonic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245206835,"owners_count":20577583,"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","json-parser","json-reader-library","python","python-json","zero-allocation"],"created_at":"2024-10-14T19:05:47.570Z","updated_at":"2025-03-24T04:18:28.810Z","avatar_url":"https://github.com/rohanrhu.png","language":"C","readme":"# python-jsonic\r\nPython bindings for [Jsonic](https://github.com/rohanrhu/jsonic) JSON reader library.\r\n\r\n## Install\r\nPIP:\r\n```bash\r\npip install pyjsonic\r\n```\r\n\r\nGit:\r\n```bash\r\ngit clone https://github.com/rohanrhu/python-jsonic\r\ncd python-jsonic\r\npython setup.py install\r\n```\r\n\r\n## Usage\r\n\r\n### Import\r\n```python\r\nimport jsonic\r\n```\r\n\r\n### Types and Functions\r\n\r\n#### Function: from_file\r\nRead file and returns `Jsonic()` object.\r\n```python\r\nroot = jsonic.from_file(\"file.json\")\r\n```\r\n\r\n#### Type: Jsonic\r\n```python\r\nroot = jsonic.Jsonic(\"[1, 2, 3, 4]\")\r\n```\r\n\r\n##### Member: Jsonic.type\r\nType member is useable for checking object and array types. Except object and array types, you will get regular python `str`, `float`, `bool` or `jsonic.Null` object.\r\n\r\n###### Type Checking\r\n###### Types\r\n`jsonic.TYPE_OBJECT`\u003cbr\u003e\r\n`jsonic.TYPE_ARRAY`\r\n\r\n`Jsonic.type` is useable for objects or arrays. Object and array values returns as `Jsonic()` objects. Null values returns as `Jsonic.Null` object. Otherwise it returns as regular python types.\r\n\r\n##### Member: Jsonic.version\r\nVersion of python-jsonic.\r\n\r\n##### Member: Jsonic.json\r\nJSON String.\r\n\r\n##### Type: Jsonic.Null\r\nJSON Null type.\r\n\r\n##### Method: root()\r\nReturns JSON root's value if `root.type` is not an array or object. Otherwise it returns None.\r\n```python\r\nroot = jsonic.Jsonic(\"1234\")\r\nprint(root.root()) # 1234\r\n\r\nroot = jsonic.Jsonic(\"\\\"foo\\\"\")\r\nprint(root.root()) # foo\r\n\r\nroot = jsonic.Jsonic(\"true\")\r\nprint(root.root()) # True\r\n\r\nroot = jsonic.Jsonic(\"null\")\r\nprint(root.root()) # jsonic.Null\r\n\r\nroot = jsonic.Jsonic(\"{}\")\r\nprint(root.root()) # None\r\nprint(root.type) # jsonic.TYPE_OBJECT\r\n\r\nroot = jsonic.Jsonic(\"[]\")\r\nprint(root.root()) # None\r\nprint(root.type) # jsonic.TYPE_ARRAY\r\n```\r\n\r\n#####  Method: len()\r\nGets length of array.\r\n\r\n#####  Method: key(key)\r\nReturns the key's value.\r\n\r\n#####  Method: item(index)\r\nReturns item of an index on array.\r\n\r\n#### Method: iterItem(index=0)\r\nIterates array item from last iterated item times index.\r\n\r\n```python\r\nroot = jsonic.Jsonic(\"[1, 2, 3, 4]\")\r\nprint(array.iterItem()) # 1\r\nprint(array.iterItem()) # 2\r\nprint(array.iterItem(1)) # 4\r\nprint(array.iterItem()) # None\r\narray.reset()\r\nprint(array.iterItem()) # 1\r\n```\r\n\r\n#### Method: iterKey(key)\r\nIterates object key from last iterated object.\r\n```python\r\nroot = jsonic.Jsonic(\"{\\\"a\\\": 1, \\\"b\\\": 2, \\\"c\\\": 3, \\\"d\\\": 4}\")\r\nprint(array.iterKey(\"a\")) # 1\r\nprint(array.iterKey(\"b\")) # 2\r\nprint(array.iterKey(\"c\")) # 3\r\nprint(array.iterKey(\"b\")) # None\r\narray.reset()\r\nprint(array.iterKey(\"b\")) # 2\r\n```\r\n\r\n#### Method: reset()\r\nResets iteration current.\r\n\r\n## Example\r\nAn example for reading JSON data\r\n\r\n```python\r\nimport jsonic\r\n\r\nroot = jsonic.from_file(\"heroes.json\")\r\n\r\nprint(\"Root Type: %d\" % root.type)\r\nprint(\"Squad: %s\" % root.iterKey(\"squadName\"))\r\nprint(\"Hometown: %s\" % root.iterKey(\"homeTown\"))\r\nprint(\"Formed: %d\" % root.iterKey(\"formed\"))\r\nprint(\"Active: %d\" % root.iterKey(\"active\"))\r\n\r\nmembers = root.iterKey(\"members\")\r\n\r\nprint(\"Members: (%d total)\" % members.len())\r\nwhile True:\r\n    member = members.iterItem()\r\n    if not member: break\r\n\r\n    name = member.iterKey(\"name\")\r\n    age = member.iterKey(\"age\")\r\n    powers = member.iterKey(\"powers\")\r\n\r\n    print(\"\\tName: %s\" % name)\r\n    print(\"\\tAge: %s\" % age)\r\n    print(\"\\tPowers (%d total):\" % powers.len())\r\n    while True:\r\n        power = powers.iterItem()\r\n        if not power:break\r\n\r\n        print(\"\\t\\t%s\" % power)\r\n\r\n    print()\r\n```\r\n\r\nExample JSON (heroes.json):\r\n```json\r\n{\r\n    \"squadName\": \"Super hero squad\",\r\n    \"homeTown\": \"Metro City\",\r\n    \"formed\": 2016,\r\n    \"secretBase\": \"Super tower\",\r\n    \"active\": true,\r\n    \"members\": [\r\n    {\r\n        \"name\": \"Molecule Man\",\r\n        \"age\": 29,\r\n        \"secretIdentity\": \"Dan Jukes\",\r\n        \"powers\": [\r\n            \"Radiation resistance\",\r\n            \"Turning tiny\",\r\n            \"Radiation blast\"\r\n        ]\r\n    },\r\n    {\r\n        \"name\": \"Madame Uppercut\",\r\n        \"age\": 39,\r\n        \"secretIdentity\": \"Jane Wilson\",\r\n        \"powers\": [\r\n            \"Million tonne punch\",\r\n            \"Damage resistance\",\r\n            \"Superhuman reflexes\"\r\n        ]\r\n    },\r\n    {\r\n        \"name\": \"Eternal Flame\",\r\n        \"age\": 1000000,\r\n        \"secretIdentity\": \"Unknown\",\r\n        \"powers\": [\r\n            \"Immortality\",\r\n            \"Heat Immunity\",\r\n            \"Inferno\",\r\n            \"Teleportation\",\r\n            \"Interdimensional travel\"\r\n        ]\r\n    }\r\n    ]\r\n}\r\n```\r\n\r\n## Syntax Checking\r\nThis library does not check JSON syntax, so you may get `SIGSEGV` or maybe infinite loops for **corrupt JSONs**. Likewise in some cases of corrupt JSONs, it would work as properly.\r\n\r\n## Performance\r\nThere are some example JSONs and reading examples in `examples/` folder for profiling the performance.\r\n\r\n## C Library\r\nYou can use [Jsonic](https://github.com/rohanrhu/jsonic) JSON reader library for C/C++.\r\n\r\n## License\r\nMIT","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohanrhu%2Fpython-jsonic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frohanrhu%2Fpython-jsonic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohanrhu%2Fpython-jsonic/lists"}