title: Creating nested Json structure with multiple key values in Python from Json
body: <p>My code is as follows:</p>
  
  <pre><code>import json
  
  def reformat(importscompanies): 
      #print importscompanies
  
      container={}
      child=[]
      item_dict={}
  
      for name, imports in importscompanies.iteritems():
          item_dict['name'] = imports
          item_dict['size'] = '500'
  
          child.append(dict(item_dict))
          container['name'] = name
          container['children'] = child
  
  if __name__ == '__main__':
      raw_data = json.load(open('data/bricsinvestorsfirst.json'))
      run(raw_data)
  
  def run(raw_data):
      raw_data2 = raw_data[0]
      the_output = reformat(raw_data2)
  </code></pre>
  
  <p>My issue is, the code isn't going through the whole file. It's only outputting one entry. Why is this? Am I rewriting something and do I need another dict that appends with every loop?</p>
  
  <p>Also, it seems as though the for loop is going through the iteritems for each dict key. Is there a way to make it pass only once?</p>
  
  <p>The issue is indeed</p>
  
  <pre><code> raw_data2 = raw_data[0]
  </code></pre>
  
  <p>I ended up creating an iterator to access the dict values.</p>
  
  <p>Thanks.</p>
  
  <p>Lastly, I'm hoping my final Json file looks this way, using the data I provided above:</p>
  
  <pre><code>{'name': u'name', 'children': [{'name': u'500 Startups', 'size': '500'}, {'name': u'AffinityChina', 'size': '500'}]}
  </code></pre>