title: Python: Add JSON into Existing JSON
body: <p>Suppose I have two json files. I would like to be able to load both, then add the entries from the second into the first. This may include adding fields or list entries. Something like the following example:</p>
  <p>file1.json:</p>
  <pre class="lang-json prettyprint-override"><code>{ &quot;fruit&quot;: [ { &quot;name&quot;: &quot;apple&quot;, &quot;color&quot;: &quot;red&quot; }, { &quot;name&quot;: &quot;orange&quot;, &quot;color&quot;: &quot;orange&quot; } ] }
  </code></pre>
  <p>file2.json:</p>
  <pre class="lang-json prettyprint-override"><code>{ &quot;fruit&quot;: [ { &quot;name&quot;: &quot;strawberry&quot;, &quot;color&quot;: &quot;red&quot;, &quot;size&quot;: &quot;small&quot; }, { &quot;name&quot;: &quot;orange&quot;, &quot;size&quot;: &quot;medium&quot; } ] }
  </code></pre>
  <p>result:</p>
  <pre class="lang-json prettyprint-override"><code>{ &quot;fruit&quot;: [ { &quot;name&quot;: &quot;apple&quot;, &quot;color&quot;: &quot;red&quot; }, { &quot;name&quot;: &quot;orange&quot;, &quot;color&quot;: &quot;orange&quot;, &quot;size&quot;: &quot;medium&quot; }, { &quot;name&quot;: &quot;strawberry&quot;, &quot;color&quot;: &quot;red&quot;, &quot;size&quot;: &quot;small&quot; } ] }
  </code></pre>
  <p>At first I thought to load them into dictionaries and try something like update:</p>
  <pre class="lang-py prettyprint-override"><code>    import simplejson
      
      filea = open(&quot;file1.json&quot;, 'r')
      dicta = simplejson.loads(filea.read())
      
      fileb = open(&quot;file2.json&quot;, 'r')
      dictb = simplejson.loads(fileb.read())
      
      filea.close()
      fileb.close()
      
      dicta.update(dictb)
  </code></pre>
  <p>Since both dictionaries have an entry for &quot;fruit&quot; I was hoping that they would merge, but it simple overrides the entry in dicta with the entry in dictb.</p>
  <p>I realize I could write code to loop through this example, but the actual files I'm using are far larger and more complicated. I was wondering if there was a library out there that did something like this already before I go reinventing the wheel. For what it's worth, I am using Python 2.6.2.</p>
  <p>Thanks for any advice or suggestions!</p>