{"id":29138718,"url":"https://github.com/bstlabs/py-jdict","last_synced_at":"2025-07-10T22:04:58.237Z","repository":{"id":43484979,"uuid":"452172051","full_name":"BstLabs/py-jdict","owner":"BstLabs","description":"JavaScript-like Python dictionary","archived":false,"fork":false,"pushed_at":"2023-01-16T17:08:21.000Z","size":485,"stargazers_count":17,"open_issues_count":13,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-30T14:11:29.866Z","etag":null,"topics":["data-structures","javascript","python"],"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/BstLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-26T06:58:49.000Z","updated_at":"2025-02-25T23:28:31.000Z","dependencies_parsed_at":"2023-02-10T05:01:23.407Z","dependency_job_id":null,"html_url":"https://github.com/BstLabs/py-jdict","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/BstLabs/py-jdict","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BstLabs%2Fpy-jdict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BstLabs%2Fpy-jdict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BstLabs%2Fpy-jdict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BstLabs%2Fpy-jdict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BstLabs","download_url":"https://codeload.github.com/BstLabs/py-jdict/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BstLabs%2Fpy-jdict/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263025795,"owners_count":23401853,"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":["data-structures","javascript","python"],"created_at":"2025-06-30T14:11:08.738Z","updated_at":"2025-07-10T22:04:58.230Z","avatar_url":"https://github.com/BstLabs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JDICT\n\nJavaScript-like Python dictionary. \nFor background and design description look at this [Medium article](https://medium.com/swlh/jdict-javascript-dict-in-python-e7a5383939ab).\n\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install `jdict` from the PyPi site:\n\n```bash\npip3 install pyjdict\n```\n\n\u003e The package name is `pyjdict`, but the module name is `jdict`.\n\n## What is jdict?\n\nLet's imagine we have some deeply nested json structure as following(this is not really deep, but it's enough for the sake of example):\n\n```json\n    {\n        \"status\": True,\n        \"data\": {\n            \"file\": {\n                \"url\": {\n                    \"short\": \"https://anonfiles.com/t3l5S2Gex3\",\n                    \"full\": \"https://anonfiles.com/t3l5S2Gex3/test_txt\",\n                },\n                \"metadata\": {\n                    \"size\": {\"bytes\": 19, \"readable\": \"19 B\"},\n                    \"name\": \"test_txt\",\n                    \"id\": \"t3l5S2Gex3\",\n                },\n            }\n        },\n    }\n```\n\nNow, you need get the `id` of this data, yes you are going to feel the pain as: `this_awesome_json[\"data\"][\"file\"][\"metadata\"][\"id\"]`.\n\nBut how about accessing this id as: `this_awesome_json.data.file.metadata.id`? Even for loop and assign values directly using .[dot] access?\n\nThat's where the jdict shines. It is lightweight, nearly zero cost library converts your dictionaries to special jdict type and you are ready to go.\n\n## Usage\n\nNow let's build small script to show the jdict. We are going to use anonymous file upload public API.\n\n```py\nimport requests\nimport json\n\nfrom jdict import jdict, set_json_decoder\n\n\n# Send post request and upload the test.txt file - you can create one\ndef _upload_file() -\u003e str:\n    file = {\"file\": open(\"test.txt\", \"rb\")}\n    result = requests.post(\"https://api.anonfiles.com/upload\", files=file)\n    result_dict = result.json()\n    # Feel the pain here\n    return result_dict[\"data\"][\"file\"][\"metadata\"][\"id\"]\n\n# Send get request and get back the json information about the uploaded file\ndef _get_file_info() -\u003e dict:\n    url = f\"https://api.anonfiles.com/v2/file/{_upload_file()}/info\"\n    return requests.get(url).json()\n\n# Change codec to use jdict\ndef _convert_to_jdict() -\u003e jdict:\n    set_json_decoder(json)\n    return _get_file_info()\n```\n\nThe killer point here is to change the codec and then convert our dictionary to jdict.\n\nIf you are using [simplejson](https://pypi.org/project/simplejson/), just pass it as `pyjdict.set_json_decoder(simplejson)`, it will do the same trick.\n\nGreat, now we are ready to use it:\n\n```py\nif __name__ == \"__main__\":\n    \"\"\"\n    Sample data:\n    {\n        \"status\": True,\n        \"data\": {\n            \"file\": {\n                \"url\": {\n                    \"short\": \"https://anonfiles.com/t3l5S2Gex3\",\n                    \"full\": \"https://anonfiles.com/t3l5S2Gex3/test_txt\",\n                },\n                \"metadata\": {\n                    \"size\": {\"bytes\": 19, \"readable\": \"19 B\"},\n                    \"name\": \"test_txt\",\n                    \"id\": \"t3l5S2Gex3\",\n                },\n            }\n        },\n    }\n    \"\"\"\n    data = _convert_to_jdict()\n    # Get the id:\n    print(\"ID: \", data.data.file.metadata.id)\n    # Use in for loop:\n    for key, value in data.data.file.metadata.items():\n        print(key, value)\n    # Set the id:\n    data.data.file.metadata.id = \"MYID\"\n    print(\"ID: \", data.data.file.metadata.id)\n\n```\n\nSample output:\n\n```sh\n$ python3 main.py\n\nID:  h8p2SbGfx2\nsize {'bytes': 19, 'readable': '19 B'}\nname test_txt\nid h8p2SbGfx2\nID:  MYID\n```\n\n## Patching\n\nThe next crucial feature is to ability to path core libraries with jdict.\n\nJust think about the boto3 library, with AWS you may encounter really deeply nested json structures, \nwith jdict you can access those nested values with `.[dot]` notation as well.\n\nBy patching `botocore.parsers` you gain really powerful tooling to work with:\n\n```py\nimport os\nimport boto3\nimport jdict\n\njdict.patch_module('botocore.parsers')\n\ndef test_library():\n    response = boto3.client('s3').list_buckets()\n    assert(response.Buckets == response['Buckets'])\n    return 'OK'\n```\n\n\u003e Just keep in mind that you need to have valid AWS credentials to run this code\n\n\n## License\n\nMIT License, Copyright (c) 2021-2022 BST LABS. See [LICENSE](LICENSE.md) file.\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbstlabs%2Fpy-jdict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbstlabs%2Fpy-jdict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbstlabs%2Fpy-jdict/lists"}