title: append new data to json file in python
body: <p>I have bellow json array in a data.json file</p>
  
  <pre><code>[{"type": "Even", "id": 1}, {"type": "Odd", "id": 2}, {"type": "Even", "id": 3}]
  </code></pre>
  
  <p>and i was trying to append new data to this json file using this code</p>
  
  <pre><code>    def foo(filename, dict_data):
      with open(filename, 'r') as json_data: 
          data = json.load(json_data)
  
      data.append(dict_data)
  
      with open(filename, 'w') as json_data: 
          json.dump(data, json_data)
  
      foo('data.json', lst)
  </code></pre>
  
  <p>but I'm getting this result </p>
  
  <pre><code>[{"id": 1, "type": "Even"}, {"id": 2, "type": "Odd"}, {"id": 3, "type": "Even"}, [{"id": 4, "type": "Even new"}, {"id": 5, "type": "Odd new"}`]]
  </code></pre>
  
  <p>but this is an invalid json data.
  <strong>my expected data is</strong> </p>
  
  <pre><code>    [{"id": 1, "type": "Even"}, {"id": 2, "type": "Odd"}, {"id": 3, "type": "Even"}, {"id": 4, "type": "Even new"}, {"id": 5, "type": "Odd new"}`]
  </code></pre>
  
  <p>what am i doing wrong.?</p>