Package: pyjdict
JDICTJavaScript-like Python dictionary.
For background and design description look at thisMedium article.InstallationUse the package managerpipto installjdictfrom the PyPi site:pip3installpyjdictThe package name ispyjdict, but the module name isjdict.What is jdict?Let'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):{"status":True,"data":{"file":{"url":{"short":"https://anonfiles.com/t3l5S2Gex3","full":"https://anonfiles.com/t3l5S2Gex3/test_txt",},"metadata":{"size":{"bytes":19,"readable":"19 B"},"name":"test_txt","id":"t3l5S2Gex3",},}},}Now, you need get theidof this data, yes you are going to feel the pain as:this_awesome_json["data"]["file"]["metadata"]["id"].But how about accessing this id as:this_awesome_json.data.file.metadata.id? Even for loop and assign values directly using .[dot] access?That'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.UsageNow let's build small script to show the jdict. We are going to use anonymous file upload public API.importrequestsimportjsonfromjdictimportjdict,set_json_decoder# Send post request and upload the test.txt file - you can create onedef_upload_file()->str:file={"file":open("test.txt","rb")}result=requests.post("https://api.anonfiles.com/upload",files=file)result_dict=result.json()# Feel the pain herereturnresult_dict["data"]["file"]["metadata"]["id"]# Send get request and get back the json information about the uploaded filedef_get_file_info()->dict:url=f"https://api.anonfiles.com/v2/file/{_upload_file()}/info"returnrequests.get(url).json()# Change codec to use jdictdef_convert_to_jdict()->jdict:set_json_decoder(json)return_get_file_info()The killer point here is to change the codec and then convert our dictionary to jdict.If you are usingsimplejson, just pass it aspyjdict.set_codec(simplejson), it will do the same trick.Great, now we are ready to use it:if__name__=="__main__":"""Sample data:{"status": True,"data": {"file": {"url": {"short": "https://anonfiles.com/t3l5S2Gex3","full": "https://anonfiles.com/t3l5S2Gex3/test_txt",},"metadata": {"size": {"bytes": 19, "readable": "19 B"},"name": "test_txt","id": "t3l5S2Gex3",},}},}"""data=_convert_to_jdict()# Get the id:print("ID: ",data.data.file.metadata.id)# Use in for loop:forkey,valueindata.data.file.metadata.items():print(key,value)# Set the id:data.data.file.metadata.id="MYID"print("ID: ",data.data.file.metadata.id)Sample output:$python3main.py

ID:h8p2SbGfx2
size{'bytes':19,'readable':'19 B'}nametest_txt
idh8p2SbGfx2
ID:MYIDPatchingThe next crucial feature is to ability to path core libraries with jdict.Just think about the boto3 library, with AWS you may encounter really deeply nested json structures,
with jdict you can access those nested values with.[dot]notation as well.By patchingbotocore.parsersyou gain really powerful tooling to work with:importosimportboto3importjdictjdict.patch_module('botocore.parsers')deftest_library():response=boto3.client('s3').list_buckets()assert(response.Buckets==response['Buckets'])return'OK'Just keep in mind that you need to have valid AWS credentials to run this codeLicenseMIT License, Copyright (c) 2021-2022 BST LABS. SeeLICENSEfile.