Traverse the dictionary and get ID recursively