Combine two JSON dictionaries in Python?
<p>I'm trying to combine two JSON dictionaries. So far I have a JSON file(myjfile.json) with the contents</p>
<pre><code>{&quot;cars&quot;: 1, &quot;houses&quot;: 2, &quot;schools&quot;: 3, &quot;stores&quot;: 4}
</code></pre>
<p>Also, I have a dictionary(mydict) in Python which looks like this:</p>
<pre><code>{&quot;Pens&quot;: 1, &quot;Pencils&quot;: 2, &quot;Paper&quot;: 3}
</code></pre>
<p>When I combine the two, they are two different dictionaries.</p>
<pre><code>with open('myfile.json' , 'a') as f:
  json.dump(mydict, f)
</code></pre>
<p>Note that the myfile.json is being written with 'a' and a /n in the code because I want to keep the contents of the file and start a new line each time it's being written to.</p>
<p>I want the final result to look like</p>
<pre><code>{&quot;cars&quot;: 1, &quot;houses&quot;: 2, &quot;schools&quot;: 3, &quot;stores&quot;: 4, &quot;Pens&quot;: 1, &quot;Pencils&quot;: 2, &quot;Paper&quot;: 3}
</code></pre>