title: Python - Appending JSON object to exisiting JSON object
body: <p>I am trying to append JSON objects to existing JSON object in text file. My first set of data look likes this.</p>
  
  <pre><code>data = [
          {
            "username": "Mike",
            "code": "12345",
            "city": "NYC"
          }
        ]
  </code></pre>
  
  <p>Then I need to append another set of JSON objects to existing file to look like this:</p>
  
  <pre><code>data = [
          {
            "username": "Mike",
            "code": "12345",
            "city": "NYC"
          },
          {
            "username": "Kelly",
            "code": "56789",
            "city": "NYC"
          }
        ]
  </code></pre>
  
  <p>When I try to run:</p>
  
  <pre><code>with open('data2.txt', 'a') as outfile:
      json.dump(data, outfile)
  </code></pre>
  
  <p>my data is not in correct JSON format. Can you please advise how to append to text file correctly?</p>