I have a list which contains data in the following format.
Data format: "1.3.4.2.1", "1.45.67.32.2", ...(the strings separated by dots
can be of varying lengths)
This strings represent the route to the "status" node and the "last index" in the string represent the value that has to be assigned to the "@default" attribute in the status node.
I have a json of the following format.
json_tree =
{
"Gardens": {
"Seaside": {
"@loc": "porch",
"@myID": "1.2.3",
"Tid": "1",
"InfoList": {
"status": {
"@default": "0",
"@myID": "26"
},
"count": {
"@default": "0",
"@myID": "1"
}
},
"BackYard": {
"@loc": "backyard",
"@myID": "75",
"Tid": "2",
"InfoList": {
"status": {
"@default": "6",
"@myID": "32"
},
"count": {
"@default": "0",
"@myID": "2"
}
}
}
}
}
}
In this case, my route list contains the following information.
route_list = ["1.2.3.26.4","1.2.3.75.32.2",...] # this json_tree could have many more layers in the format shown above
Note: '1.2.3.26" is the route to the "status" node in "Gardens" and "4" is the value to be assigned to the "@default" node in the "status".
Note: '1.2.3.75.32" is the route to the "status" node in "BackYard" and "2" is the value to be assigned to the "@default" node in the "status".
As of now, I have the following method. I am unable to move further from here.
for item in route_list:
UpdateJsonTree(json_tree, item)
def UdpateJsonTree(json_tree, item):
# I am unsure on how to parse the json tree based on the route given
# and update the '@default' value of the status node
Any help would be appreciated. Thanks.