I’m trying to encrypt all the data inside the json, I need the program to encrypt the data if it’s anything other than a dict, but recursively modify it in the dicts inside the json, here’s an example:
// Original JSON
{
"id": "00000000",
"size": 5,
"data": {
"name": "example",
"date": "00-00-0000"
}
}
After the function:
{
"id": "!(&$#*)@(DJ(UDIS)(@",
"size": "()*#@EJD",
"data": {
"name": "(#*JR#(WD)*@DAS&HD$F",
"date": "A*(&SDU(*AJSC"
}
}
This is the code I’ve tried, but it isn’t recursive.
async def insert_one(self, collection: str, json: dict):
enc_json = {
self.encryption.encrypt(key): self.encryption.encrypt(value)
for key, value in json.items()
}
return await self.database["Disect"][collection].insert_one(enc_json)