title: SyntaxError: Unexpected token < in JSON at position 0 at Object.parse (native) (AngularJS)
body: <p>I'm successfully saving my data into a json file with a php script (save-data.php) but I'm unable to fetch it correctly with my get-data.php script.</p>
  
  <p><strong><em>Error message:</em></strong> angular.js:12520 SyntaxError: Unexpected token &lt; in JSON at position 0 at Object.parse (native)</p>
  
  <p><strong>save-data.php</strong>:</p>
  
  <pre><code>&lt;?php
  
  $json = file_get_contents("php://input");
  
  $file = fopen('C:/test/save-data.json','w+');
  
  fwrite($file, $json);
  
  fclose($file);
  
  ?&gt;
  </code></pre>
  
  <p><strong>get-data.php</strong>:</p>
  
  <pre><code>&lt;?php
  
  //header('Content-Type: application/json');
  
  $json = file_get_contents('C:/test/save-data.json');
  
  //Decode JSON
  //$json_data = json_decode($json, true);
  
  //Print data
  echo $json
  
  ?&gt;
  </code></pre>
  
  <p><strong>save-data.json</strong>:</p>
  
  <pre><code>{
    "id": "179",
    "var1": "variable1",
    "var2": "variable2"
  }
  </code></pre>
  
  <p><strong>sample controller</strong>:</p>
  
  <pre><code>// save data (myModel: id, var1, var2)
    $scope.save = function() {
      console.log('Creating a JSON');
      $scope.jsonString = angular.toJson($scope.myModel, true);
      $http.post('save-data.php', $scope.jsonString).then(function(data) {
        $scope.msg1 = 'Data saved';
      });
      $scope.msg2 = 'Data sent: '+ $scope.jsonString;
    };
  
  // get data
    $scope.get = function() {
      $http.get('get-data.php').then(function(data) {
        //$scope.my_data = JSON.parse(data);
        console.log(data.data);
      });
    };
  </code></pre>
  
  <p><strong><em>EDIT: I didn't need to decode the json file to json nor to parse it (all commented in scripts).</em></strong></p>