title: Append data to a .JSON file with PHP
body: <p>I have this .json file:</p>
  
  <pre><code>[
      {
          "id": 1,
          "title": "Ben\\'s First Blog Post",
          "content": "This is the content"
      },
      {
          "id": 2,
          "title": "Ben\\'s Second Blog Post",
          "content": "This is the content"
      }
  ]
  </code></pre>
  
  <p>This is my PHP code:</p>
  
  <pre><code>&lt;?php
  $data[] = $_POST['data'];
  
  $fp = fopen('results.json', 'a');
  fwrite($fp, json_encode($data));
  fclose($fp);
  </code></pre>
  
  <p>The thing is, I'm not exactly sure how to achieve it. I'm going to call this code above every time a form is submitted, so I need the ID to increment and to also keep the valid JSON structure with <code>[</code> and <code>{</code>, is this possible?</p>