title: Iterate through Json most efficiently using Python
body: <p>I want to make sure I am iterating through a Json file most efficiently. Seems I have to many &quot;for&quot; loops. Possibly a better, more expert way, to loop through json with some &quot;if&quot; conditions? The goal is to flatten the json file to a customizes dict.</p>
  <p>Example Json:</p>
  <pre><code>{
      &quot;Tier1&quot;: [
          {
              &quot;Tier2_A&quot;: {&quot;id&quot;: &quot;11111&quot;},
              &quot;Tier2_B&quot;: [],
              &quot;Tier2_C&quot;: [
                  {
                      &quot;Sub_Tier_C1&quot;: {&quot;id&quot;: &quot;22222&quot;},
                      &quot;Sub_Tier_C2&quot;: [
                          {
                              &quot;Id_1&quot;: &quot;78965&quot;,
                              &quot;Id_2&quot;: &quot;28493&quot;,
                          },
                          {
                              &quot;Id_1&quot;: &quot;49382&quot;,
                              &quot;Id_2&quot;: &quot;434234&quot;,
                          }
                      ]}
  </code></pre>
  <p>Example Python Code:</p>
  <pre><code>store = {}
  jsonload = get_json_load()
  
  for Tier1, Tier1_List in jsonload.items():
      store[Tier1] = set()
  
      for Tier1_Dict in Tier1_List:
          if Tier1_Dict[&quot;Tier2_C&quot;]:
              for Tier1_Dict_Dict in Tier1_Dict[&quot;Tier2_C&quot;]:
                  for Tier1_Dict_Dict_Dict in Tier1_Dict_Dict[&quot;Sub_Tier_C2&quot;]:
                      if Tier1_Dict_Dict_Dict == &quot;Id_1&quot;:
                          store[Tier1].add((Tier1_Dict[&quot;Tier2_A&quot;][&quot;id&quot;], Tier1_Dict_Dict_Dict[&quot;Id_1&quot;]))
                      elif Tier1_Dict_Dict_Dict == &quot;Id_2&quot;:
                          store[Tier1].add((Tier1_Dict[&quot;Tier2_A&quot;][&quot;id&quot;], Tier1_Dict_Dict_Dict[&quot;Id_2&quot;]))
  
  return store
  </code></pre>