import json
# Ваш условный результат
tmp = {
'EMS/Data/defaultVars.blabla': {
'login': 'afsdfa',
'users': 'afsdfa',
'blala': 'afsdfa',
},
'EMS/Logs/defaultVars.blabla': {
'login': 'afsdfa',
'users': 'afsdfa',
'blala': 'afsdfa',
},
'EMS/External/defaultVars.blabla': {
'login': 'afsdfa',
'users': 'afsdfa',
'blala': 'afsdfa',
},
'Blabla/Data/defaultVars.blabla': {
'login': 'afsdfa',
'users': 'afsdfa',
'blala': 'afsdfa',
},
}
new_dict = {}
def append_value(modifier_dict: dict, key, value):
if len(key) > 1:
modifier_dict[key[0]] = append_value(modifier_dict.get(key[0], {}), key[1:], value)
else:
modifier_dict[key[0]] = value
return modifier_dict
for k, v in tmp.items():
append_value(new_dict, k.split('/'), v)
# Новый результат
print(json.dumps(new_dict, indent=4))
{
"EMS": {
"Data": {
"defaultVars.blabla": {
"login": "afsdfa",
"users": "afsdfa",
"blala": "afsdfa"
}
},
"Logs": {
"defaultVars.blabla": {
"login": "afsdfa",
"users": "afsdfa",
"blala": "afsdfa"
}
},
"External": {
"defaultVars.blabla": {
"login": "afsdfa",
"users": "afsdfa",
"blala": "afsdfa"
}
}
},
"Blabla": {
"Data": {
"defaultVars.blabla": {
"login": "afsdfa",
"users": "afsdfa",
"blala": "afsdfa"
}
}
}
}