title: Auto increment id JSON
body: <p>I'm making a RESTful webservice and I want the items that are posted to the JSON file to have an Id. I've been searching everywhere but couldn't find anything on how to do this.</p>
  
  <p>The JSON looks like this</p>
  
  <pre><code>[
      {
          "id": "2",
          "title": "Hello World",
          "artist": "John Smith",
          "genre": "pop",
          "week": "4",
          "highest_rating": "3",
          "year": "2014",
          "youtube": "www",
          "links": [
              {
                  "rel": "self",
                  "href": ""
              },
              {
                  "rel": "collection",
                  "href": ""
              }
          ]
      },
      {
          "id": "3",
          "title": "Lorem Ipsum",
          "artist": "John Smith",
          "genre": "pop",
          "week": "4",
          "highest_rating": "3",
          "year": "2014",
          "youtube": "www",
          "links": [
              {
                  "rel": "self",
                  "href": ""
              },
              {
                  "rel": "collection",
                  "href": ""
              }
          ]
      }
  ]
  </code></pre>
  
  <p>The id's in this file are hardcoded.
  Can someone please tell me how to get id's with auto increment</p>
  
  <p><strong>Edit</strong>
  I see I've been unclear in explaining what I want to do.</p>
  
  <p>Data that is posted to the webservice, is stored in a .json file. I'm not using a DB. 
  So in PHP, this is what I'm doing.</p>
  
  <pre><code>$file = file_get_contents("data.json");
      $data = json_decode($file, true);
  
  
      $data[] = array(
          'id'=&gt;$_POST["id"],
          'title'=&gt;$_POST["title"],
          'artist'=&gt;$_POST["artist"],
          'genre'=&gt;$_POST["genre"],
          'week'=&gt;$_POST["week"],
          'highest_rating'=&gt;$_POST["highest_rating"],
          'year'=&gt;$_POST["year"],
          'youtube'=&gt;$_POST["youtube"],
          "links"=&gt; [ array(
                  "rel"=&gt;"self",
                  "href"=&gt;""
              ),
              array(
                 "rel"=&gt;"collection",
                  "href"=&gt;""
              )
          ]
      );
  
      file_put_contents('data.json',json_encode($data));
  </code></pre>
  
  <p>So at the moment the id is given through a POST but I want it to be given with auto-increment.
  I hope this makes my question clearer.</p>