I have Json file which Looks like Below. To get the list (given in example1,example2 and further) , I have to write nested for loop 5-6 times. Is there any easy way to write the code and get the end list ?
Example of Json file
{
"SecureConfig" :[
{
"Test" : [
{
"Test1" : [
{
"example1" : ["ls","cat abc.txt | grep wc -l"]
},
{
"example2" : ["ls","cat abc.txt | grep wc -l"]
}
],
"Test2" : [
{
"example3" : ["ls","cat abc.txt | grep wc -l"]
},
{
"example4" : ["ls","cat abc.txt | grep wc -l"]
}
]
}
]
}
]}
Loop that I have created is :-
config_file = open(FILE)
data = json.load(config_file)
for index in range(len(data[module])):
for ModuelName in data[module][index]:
ModuleValue=data[module][index][ModuelName]
for index2 in range(len(ModuleValue)):
for SubModuleName in ModuleValue[index]:
SubModuleValue=ModuleValue[index2][SubModuleName]
for index3 in range(len(SubModuleValue)):
for keys3 in SubModuleValue[index3]:
print (SubModuleValue[index3][keys3])