title: javascript parse.json error with data from php json_encode
body: <p>I've a very nasty problem sending data from PHP to Javascript.</p>
  
  <p>Long story short... I get some data from a DB then convert all to json and send all to a javascript function.</p>
  
  <p>One of the column from the DB contain data that look like:</p>
  
  <pre><code>val01\test\val04
  </code></pre>
  
  <p>I assign these data to an array then using json_encode convert everything to json, like in this example:</p>
  
  <pre><code>$result = 'val01\test\val04'; //these are the data that are get from DB
  $example = ['testData' =&gt; $result];
  json_encode($example);
  </code></pre>
  
  <p>At the end I've these data:</p>
  
  <pre><code>{"testData":"val01\\test\\val04\\"}
  </code></pre>
  
  <p>now, when i use these result with parse.json like this:</p>
  
  <pre><code>var json = '{"testData":"val01\\test\\val04\\"}';
  obj = JSON.parse(json);
  </code></pre>
  
  <p>I receive an error:</p>
  
  <pre><code>Error: Unexpected token v in JSON at position 24
  </code></pre>
  
  <p>seem that the slashes are escaped incorrectly... To be sure that is not my fault with something else.. I test my example also on MDN sample page (<a href="https://developer.mozilla.org/it/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse" rel="nofollow noreferrer">https://developer.mozilla.org/it/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse</a>) that return same result.</p>
  
  <p>How can I solve this problem? </p>
  
  <p>I won't create my own escape function.. is too dangerous from my point of view.. I never know what kind of data I will can find in this columns so.. there is a clean way to handle this problem?</p>
  
  <p>thank you</p>