dict1 = {
"system.cpu.user.pct": {
"value": 12.83
},
"system.load.1": {
"value": 0.33
}
}
dict2 = {
"system": {
"cpu": {
"user": {
"pct": 12.83
}
},
"load": {
"1": 0.33
}
}
}
after doing it for a few days, I finally took care of it myself, or I was too lame. Here is my solution:
import json
def add_key(dict, field):
keys = field.split(".")
length = len(keys)
number = 0
for key in keys:
if number != length - 1:
dict = dict.setdefault(key, {})
else:
dict[key] = dict1[field]["value"]
number += 1
report = {}
for field in dict1.keys():
add_key(report, field)
print report