I have a JSON response coming back which does a general structure, however, they can be N number of nested results ('queues'). I'm trying to understand how I can loop through all of the nested results which could go extremely deep. I included a link to trinket with the long JSON response. Basically, there are N number of leaf queues that can have no limit, so how can i keep looping deeper? Right now i get stuck as 2 levels down.
import json
with open('sample_response.json') as data_file:
theJSON = json.load(data_file)
queuesJson = theJSON['scheduler']['schedulerInfo']['queues']['queue']
def get_leaf_queue_info (childQueue):
for queue in childQueue:
print ('nested +' + queue.get('queueName'))
for queue in queuesJson:
print (queue.get('queueName'))
if (len(queue['queues']['queue']) > 1):
get_leaf_queue_info(queue['queues']['queue'])