I have a list of lists with several lines like this (the example below shows line 4 out of 178):
result[4]
['activity',
'root',
'children',
0,
'children',
0,
'children',
0,
'children',
0,
'children',
0,
'children',
0,
'visibility']
I would like to convert the structure above into something like this:
['activity']['root']['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['visibility']
So that it can be used in a loop to access nodes in a heavily nested JSON file.
What I envisage is something like this:
def convert_to_path(list):
do stuff
return valid_path
def use_converted_path(json_data, converted_path):
do stuff
return
The function would then return the same as if I did json_data['activity']['root']['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['children'][0]['visibility']
original_list = result[4]
valid_path = convert_to_path(original_list)
use_converted_path(valid_path) (output the JSON value )
I see it as a two functions job but I'm open to any suggestions!