title: PHP JSON String, escape Double Quotes for JS output
body: <p>I'm creating a JSON string from a PHP array. I've encoded it using <code>json_encode()</code>.</p>
  
  <pre><code>$data = array(
      'title' =&gt; 'Example string\'s with "special" characters'
  );
  
  $data = json_encode( $data );
  </code></pre>
  
  <p><code>$data</code> is localized using <code>wp_localize_script()</code> and is accessible via a global <code>data</code> variable.</p>
  
  <p>In the JS file I can access the information by the following:</p>
  
  <pre><code>var data     = data.replace( /&amp;quot;/g, '"' ),
      jsonData = jQuery.parseJSON( data );
  
  console.log( jsonData );
  </code></pre>
  
  <p>This results in an output of:</p>
  
  <pre><code>{ "title":"Example string's with "special" characters" }
  </code></pre>
  
  <p>Entering that result into <a href="http://jsonlint.com/" rel="noreferrer">http://jsonlint.com/</a> returns an error. Removing the double quotes around "special" validates the string.</p>
  
  <p>What is the best way to create a JSON string from PHP and properly escape it for use in a JS file?</p>