title: How do I json_decode string with special chars (" \\ " )
body: <p>I have a problem with encoding and decoding json data. In js I send query with data type 'json', it looks like this:</p>
  
  <pre><code>{\"front\":{\"0\":{\"type\":\"text\",\"width\":\"55px\",\"height\":\"27px\",\"top\":\"151px\",\"left\":\"86px\",\"zIndex\":\"1\",\"svg\":\"&lt;svg width=\\\"54.9375\\\" height=\\\"27.09375\\\" viewBox=\\\"0 0 54.9375 27.09375\\\" xmlns=\\\"http://www.w3.org/2000/svg\\\" xmlns:xlink=\\\"http://www.w3.org/1999/xlink\\\"&gt;&lt;g id=\\\"0.7882792934370437\\\"&gt;&lt;text fill=\\\"#FF0000\\\" stroke=\\\"none\\\" stroke-width=\\\"0\\\" stroke-linecap=\\\"round\\\" stroke-linejoin=\\\"round\\\" x=\\\"\\\" y=\\\"\\\" text-anchor=\\\"start\\\" font-size=\\\"24px\\\" font-family=\\\"arial\\\" data-textcurve=\\\"1\\\" data-itemzoom=\\\"1 1\\\" data-textspacing=\\\"0\\\"&gt;&lt;textPath xmlns:xlink=\\\"http://www.w3.org/1999/xlink\\\" xlink:href=\\\"http://138.68.62.219/Buy-Hanes-T-shirt-PC61LS#textPath-item-0\\\"&gt;&lt;tspan dy=\\\"0\\\"&gt;Hello&lt;/tspan&gt;&lt;/textPath&gt;&lt;/text&gt;&lt;/g&gt;&lt;defs&gt;&lt;path id=\\\"textPath-item-0\\\" d=\\\"M 0.125 22.117808976867764 A 3093.9720937064453 3093.9720937064453 0 0 1 54.124314613414626 22.117808976867764\\\"&gt;&lt;/path&gt;&lt;/defs&gt;&lt;/svg&gt;\",\"rotate\":0,\"text\":\"Hello\",\"color\":\"#FF0000\",\"fontFamily\":\"arial\",\"align\":\"center\",\"outlineC\":\"none\",\"outlineW\":0}}
  </code></pre>
  
  <p>Then I save it to cell in <code>MySQL</code>, it looks like this: </p>
  
  <pre><code>{\\&amp;quot;front\\&amp;quot;:{\\&amp;quot;0\\&amp;quot;:{\\&amp;quot;type\\&amp;quot;:\\&amp;quot;text\\&amp;quot;,\\&amp;quot;width\\&amp;quot;:\\&amp;quot;55px\\&amp;quot;,\\&amp;quot;height\\&amp;quot;:\\&amp;quot;27px\\&amp;quot;,\\&amp;quot;top\\&amp;quot;:\\&amp;quot;151px\\&amp;quot;,\\&amp;quot;left\\&amp;quot;:\\&amp;quot;86px\\&amp;quot;,\\&amp;quot;zIndex\\&amp;quot;:\\&amp;quot;1\\&amp;quot;,\\&amp;quot;svg\\&amp;quot;:\\&amp;quot;&amp;lt;svg width=\\\\\\&amp;quot;54.9375\\\\\\&amp;quot; height=\\\\\\&amp;quot;27.09375\\\\\\&amp;quot; viewBox=\\\\\\&amp;quot;0 0 54.9375 27.09375\\\\\\&amp;quot; xmlns=\\\\\\&amp;quot;http:\/\/www.w3.org\/2000\/svg\\\\\\&amp;quot; xmlns:xlink=\\\\\\&amp;quot;http:\/\/www.w3.org\/1999\/xlink\\\\\\&amp;quot;&amp;gt;&amp;lt;g id=\\\\\\&amp;quot;0.7882792934370437\\\\\\&amp;quot;&amp;gt;&amp;lt;text fill=\\\\\\&amp;quot;#FF0000\\\\\\&amp;quot; stroke=\\\\\\&amp;quot;none\\\\\\&amp;quot; stroke-width=\\\\\\&amp;quot;0\\\\\\&amp;quot; stroke-linecap=\\\\\\&amp;quot;round\\\\\\&amp;quot; stroke-linejoin=\\\\\\&amp;quot;round\\\\\\&amp;quot; x=\\\\\\&amp;quot;\\\\\\&amp;quot; y=\\\\\\&amp;quot;\\\\\\&amp;quot; text-anchor=\\\\\\&amp;quot;start\\\\\\&amp;quot; font-size=\\\\\\&amp;quot;24px\\\\\\&amp;quot; font-family=\\\\\\&amp;quot;arial\\\\\\&amp;quot; data-textcurve=\\\\\\&amp;quot;1\\\\\\&amp;quot; data-itemzoom=\\\\\\&amp;quot;1 1\\\\\\&amp;quot; data-textspacing=\\\\\\&amp;quot;0\\\\\\&amp;quot;&amp;gt;&amp;lt;textPath xmlns:xlink=\\\\\\&amp;quot;http:\/\/www.w3.org\/1999\/xlink\\\\\\&amp;quot; xlink:href=\\\\\\&amp;quot;http:\/\/138.68.62.219\/Buy-Hanes-T-shirt-PC61LS#textPath-item-0\\\\\\&amp;quot;&amp;gt;&amp;lt;tspan dy=\\\\\\&amp;quot;0\\\\\\&amp;quot;&amp;gt;Hello&amp;lt;\/tspan&amp;gt;&amp;lt;\/textPath&amp;gt;&amp;lt;\/text&amp;gt;&amp;lt;\/g&amp;gt;&amp;lt;defs&amp;gt;&amp;lt;path id=\\\\\\&amp;quot;textPath-item-0\\\\\\&amp;quot; d=\\\\\\&amp;quot;M 0.125 22.117808976867764 A 3093.9720937064453 3093.9720937064453 0 0 1 54.124314613414626 22.117808976867764\\\\\\&amp;quot;&amp;gt;&amp;lt;\/path&amp;gt;&amp;lt;\/defs&amp;gt;&amp;lt;\/svg&amp;gt;\\&amp;quot;,\\&amp;quot;rotate\\&amp;quot;:0,\\&amp;quot;text\\&amp;quot;:\\&amp;quot;Hello\\&amp;quot;,\\&amp;quot;color\\&amp;quot;:\\&amp;quot;#FF0000\\&amp;quot;,\\&amp;quot;fontFamily\\&amp;quot;:\\&amp;quot;arial\\&amp;quot;,\\&amp;quot;align\\&amp;quot;:\\&amp;quot;center\\&amp;quot;,\\&amp;quot;outlineC\\&amp;quot;:\\&amp;quot;none\\&amp;quot;,\\&amp;quot;outlineW\\&amp;quot;:0}}
  </code></pre>
  
  <p>When I read with php this data that's what I see ( <code>$tmp=$products[0]['design_file']; print_r($tmp);</code>) :</p>
  
  <pre><code>"{\\"front\\":{\\"0\\":{\\"type\\":\\"text\\",\\"width\\":\\"55px\\",\\"height\\":\\"27px\\",\\"top\\":\\"151px\\",\\"left\\":\\"86px\\",\\"zIndex\\":\\"1\\",\\"svg\\":\\"&lt;svg width=\\\\\\"54.9375\\\\\\" height=\\\\\\"27.09375\\\\\\" viewBox=\\\\\\"0 0 54.9375 27.09375\\\\\\" xmlns=\\\\\\"http:\/\/www.w3.org\/2000\/svg\\\\\\" xmlns:xlink=\\\\\\"http:\/\/www.w3.org\/1999\/xlink\\\\\\"&gt;&lt;g id=\\\\\\"0.7882792934370437\\\\\\"&gt;&lt;text fill=\\\\\\"#FF0000\\\\\\" stroke=\\\\\\"none\\\\\\" stroke-width=\\\\\\"0\\\\\\" stroke-linecap=\\\\\\"round\\\\\\" stroke-linejoin=\\\\\\"round\\\\\\" x=\\\\\\"\\\\\\" y=\\\\\\"\\\\\\" text-anchor=\\\\\\"start\\\\\\" font-size=\\\\\\"24px\\\\\\" font-family=\\\\\\"arial\\\\\\" data-textcurve=\\\\\\"1\\\\\\" data-itemzoom=\\\\\\"1 1\\\\\\" data-textspacing=\\\\\\"0\\\\\\"&gt;&lt;textPath xmlns:xlink=\\\\\\"http:\/\/www.w3.org\/1999\/xlink\\\\\\" xlink:href=\\\\\\"http:\/\/138.68.62.219\/Buy-Hanes-T-shirt-PC61LS#textPath-item-0\\\\\\"&gt;&lt;tspan dy=\\\\\\"0\\\\\\"&gt;Hello&lt;\/tspan&gt;&lt;\/textPath&gt;&lt;\/text&gt;&lt;\/g&gt;&lt;defs&gt;&lt;path id=\\\\\\"textPath-item-0\\\\\\" d=\\\\\\"M 0.125 22.117808976867764 A 3093.9720937064453 3093.9720937064453 0 0 1 54.124314613414626 22.117808976867764\\\\\\"&gt;&lt;\/path&gt;&lt;\/defs&gt;&lt;\/svg&gt;\\",\\"rotate\\":0,\\"text\\":\\"Hello\\",\\"color\\":\\"#FF0000\\",\\"fontFamily\\":\\"arial\\",\\"align\\":\\"center\\",\\"outlineC\\":\\"none\\",\\"outlineW\\":0}}
  </code></pre>
  
  <p>If I do this:</p>
  
  <pre><code>$tmp=$products[0]['design_file'];
  $info=json_decode($tmp);
  print_r($info);
  </code></pre>
  
  <p>It gives me <strong>Null</strong>.
  How can I get my array back from that mess?</p>
  
  <p>Javascript sending:</p>
  
  <pre><code>jQuery(document).triggerHandler( "before.addtocart.design", datas);
  var finaldata=JSON.stringify(datas);
      jQuery.ajax({
      url: 'index.php?route=checkout/cart/add', //URL TO CONTROL FUNCTION add()
      type: 'post',
      data: 'product_id=' + product_id + '&amp;quantity=' + q+"&amp;option['options']="+finaldata,
  </code></pre>
  
  <p>Read in Php </p>
  
  <pre><code>if (isset($this-&gt;request-&gt;post['option'])) {
              $option = array_filter($this-&gt;request-&gt;post['option']);
  </code></pre>
  
  <p>Pass to view</p>
  
  <pre><code>$data['products'][] = array(
                  'design_file'=&gt;$product['design_file'],
  ...
  $tmp=$products[0]['design_file'];
  </code></pre>