title: Writing JSON data to a text file, data sent via .post jQuery to PHP file
body: <p>I want to write JSON data to a text file using jQuery and PHP. I send the data from JavaScript to a PHP file using</p>
  
  <pre><code>function WriteToFile(puzzle)
      {
      $.post("saveFile.php",{ 'puzzle': puzzle },
          function(data){
              alert(data);
          }, "text"
      );
      return false;
      }
  </code></pre>
  
  <p>The PHP file is </p>
  
  <pre><code>&lt;?php
  $thefile = "new.json"; /* Our filename as defined earlier */
  $towrite = $_POST["puzzle"]; /* What we'll write to the file */
  echo $towrite;
  $openedfile = fopen($thefile, "w");
  $encoded = json_encode($towrite);
  fwrite($openedfile, $encoded);
  fclose($openedfile);
  return "&lt;br&gt; &lt;br&gt;".$towrite;
  
  ?&gt;
  </code></pre>
  
  <p>This works but the output in the file <code>new.json</code> looks like this: </p>
  
  <pre><code>"{\\\"answers\\\":[\\\"across\\\",\\\"down\\\"],\\\"clues\\\":[],\\\"size\\\":[10,10]}"
  </code></pre>
  
  <p>I don't want those slashes: how did I get them?</p>