title: Remove first character from JSON object using PHP
body: <p>I'm developing a Chrome Extension in which I send JSON with jQuery to a PHP file, which writes it into a JSON file.</p>
  
  <p>My jQuery JSON object:</p>
  
  <pre><code>var detailsArray = { title : [{
                       "title" : title,
                       "url" : url, 
                       "username" : username, 
                       "password" : password
                     }]
  };
  </code></pre>
  
  <p>My PHP code:</p>
  
  <pre><code>&lt;?php
  $dataToBeInserted = $_POST;
  $file = "JSON.json";
  
  //Open the file with read/write permission or show text
  $fh = fopen($file, 'a+') or die("can't open file");
  $stat = fstat($fh);
  
  //Remove the last } character from the JSON file
  ftruncate($fh, $stat['size']-1);
  
  //Add the data from $dataToBeInserted to the file with a comma before it if there is data in file already.
  if ($stat['size'] != 0) $append = ",";
  echo fwrite($fh, $append . json_encode($dataToBeInserted,JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
  echo fwrite($fh, "}");
  
  //Close the file
  fclose($fh);
  ?&gt;
  </code></pre>
  
  <p>My JSON file:</p>
  
  <pre><code>{
  "Log In | Guild Wars 2" : [{
      "url" : "https://account.guildwars2.com/login", 
      "username" : "Guildwars2isawesome", 
      "password" : "randompassword",
      "title" : "Log In | Guild Wars 2"
  }],
  "library genesis" : [{
      "url" : "http://gen.lib.rus.ec/", 
      "username" : "awesomesauce", 
      "password" : "applesauce",
      "title" : "library genesis"
  }],
  "Google" : [{
      "url" : "http://www.google.com", 
      "username" : "someone@gmail.com", 
      "password" : "stackoverflowrules",
      "title" : "Google"
  }]
  }
  </code></pre>
  
  <p>After I add the JSON to the file, the JSON becomes this:</p>
  
  <pre><code>{
  "Log In | Guild Wars 2" : [{
      "url" : "https://account.guildwars2.com/login", 
      "username" : "Guildwars2isawesome", 
      "password" : "randompassword",
      "title" : "Log In | Guild Wars 2"
  }],
  "library genesis" : [{
      "url" : "http://gen.lib.rus.ec/", 
      "username" : "awesomesauce", 
      "password" : "applesauce",
      "title" : "library genesis"
  }],
  "Google" : [{
      "url" : "http://www.google.com", 
      "username" : "someone@gmail.com", 
      "password" : "stackoverflowrules",
      "title" : "Google"
  }]
  ,{
      "title": [
          {
              "title": "jQuery.getJSON() | jQuery API Documentation",
              "url": "http://api.jquery.com/jquery.getjson/",
              "username": "",
              "password": ""
          }
      ]
  }}
  </code></pre>
  
  <p>The problem is that the JSON I'm writing in jQuery has to have a <code>{</code> at the start of the object to not throw an error while I'm sending it. Is there any way to remove this first <code>{</code> of the object I'm writing to the file, without breaking the code?</p>