title: Python add new element to existing JSON File
body: <p>I'm trying to append some data into a JSON file inside python.
  It should add the CVE-ID into my customer JSON file.</p>
  
  <p>I wasn't able to solve this by myself. If I print my dict after appending it shows the expected result.
  But it seems, that the file will not be written after the append. I have also tried to use <code>json.dump()</code> after the "appending-line" - but also without success.</p>
  
  <p>At the moment my code looks like this:</p>
  
  <pre><code>with open("test.json", "r+") as customerdata:
      customers_json = json.load(customerdata)
  
  # some other code here...
  
  if cve["cve"]["CVE_data_meta"]["ID"] not in customer["customer"]["already-sent-cve"]:
                  customers_json["customers"][0]["customer"]["already-sent-cve"].append(cve["cve"]["CVE_data_meta"]["ID"])
  </code></pre>
  
  <p>My JSON file looks like this:</p>
  
  <pre><code>    {
          "customers":[
              {
                  "customer":{
                      "id":"1",
                      "company-name":"test GmbH",
                      "alert-email":"xyz@googlemail.com",
                      "using":[
                          "xxx",
                          "xyz"
                      ],
                      "already-sent-cve":[
                          "CVE-2013-3738"
                          # here new CVE
                      ]
                  }
              },
          {
              "customer":{
                  "id":"2",
                    ...
            }
      ]
  }
  </code></pre>
  
  <p>FYI: There is another JSON file with the CVE's from which file I'm collecting the data. </p>
  
  <p>Any suggestions how to solve this?</p>
  
  <p>Regards.</p>
  
  <h2>EDIT:</h2>
  
  <p>Was able to solve this:</p>
  
  <pre><code>with open("test.json", "w") as customerdata:
      customers_json["customers"][0]["customer"]["already-sent-cve"].append(cve["cve"]["CVE_data_meta"]["ID"])
      json.dump(customers_json, customerdata, indent=2)
  </code></pre>