title: How to avoid backslashes in JSON returned from PHP?
body: <p>I'm having some trouble with the code below. the console log returns: </p>
  
  <pre><code>"returningList{"view":0,"new":1,"random":1} result: "{\"view\":0,\"new\":1,\"random\":1}""
  </code></pre>
  
  <p>As you can see it's acquiring backslashes that make it no longer JSON, despite specifying <code>datatype : 'json'</code>. </p>
  
  <p>The problem seems to be occurring where the result is read back in from PHP to javascript, because if I write <code>$jsonArr</code> to MySQL before echoing it then the SQL data shows the correct string (i.e. without the backslashes).</p>
  
  <p>Please help because this apparent insanity is really winding me up. All I want to do is get my data back – In my actual code I don't normally return the JSON I passed in as data, but here it suffices to prove the point. I thought that the <code>'json'</code> datatype would mean that it would accept echoed JSON without corrupting it.</p>
  
  <p>Apologies for the following bluntness, but in response to similar questions I've seen people just say "it escapes the quotes", as if that that answers the question – in this case at least it seems that it doesn't: Obviously (AFAIK) that's where the backslashes are coming from, but the quotes are part of the JSON syntax (which it knows it's expecting), not part of the field content, so they clearly shouldn't be escaped. I need a <strong>solution</strong> please. Thanks.</p>
  
  <pre><code>window.newGot = listBuild({
      'view' : 0,
      'new' : 1,
      'random' : 1
  });
  
  function listBuild(options)
      //Fill the new list.
      return $.ajax({
          type : "POST",
          url : "./php/getList.php",
          cache : false,
          data : {
              options : JSON.stringify(options)
          },
          datatype : "json"
      }).then(function(jsonList) {
          console.log('returningList' + JSON.stringify(options) + ' result: ' + JSON.stringify(jsonList));
          return jsonList;
      });
  }
  </code></pre>
  
  <p>Here's the php file contents:</p>
  
  <pre><code>&lt;?php
  $options = json_decode($_POST['options'], true);
  $jsonArr = json_encode($options);
  echo $jsonArr;
  </code></pre>