I'm current working a script that takes an Android application's metadata as a nested dictionary and inserts it to MongoDB. However, since some of the keys include '.'
s (due to component names in the APK file), which unfortunately isn't accepted by MongoDB in the version being dealt with. Currently trying to write a recursive script which replace the '.'
s to '/'
s of the keys in the dict data being inserted, but some keys still aren't changed to fit the requirements.
def fixKeys(dictionary):
for k,v in dictionary.items():
if isinstance(v, dict):
if '.' in k:
dictionary[k.replace('.','/')] = dictionary.pop(k)
fixKeys(v)
else:
if '.' in k:
dictionary[k.replace('.','/')] = dictionary.pop(k)
return dictionary
Example input:
data = {"gender":"male","name.data": {"last.name":"Arabulut","first.name":"Altay","parents.names":{"father.name":"John","mother.name":"Jennifer"}}, "birthday.data":{"birthday.day":"01","birthday.month":"03","birthday.year":"1977"}}
Any idea as to what might be missing?