title: How can I put double quotes inside a string within an ajax JSON response from php?
body: <p>I receive a JSON response in an Ajax request from the server. This way it works:</p>
  
  <p>{ "a" : "1", "b" : "hello 'kitty'" } </p>
  
  <p>But I did not succeed in putting double quotes around <em>kitty</em>.</p>
  
  <p>When I convert " to \x22 in the Ajax response, it is still interpreted as " by JavaScript and I cannot parse the JSON.</p>
  
  <p>Should I also escape the \ and unescape later (which would be possible)?</p>
  
  <p>How to do this?</p>
  
  <p><em>Edit:</em> I am not sure if i expressed it well: I want this string inside of "b" <em>after</em> the parse:</p>
  
  <p>hello "kitty"</p>
  
  <p>If necessary I could also add an additional step after the parse to convert "b", but I guess it is not necessary, there is a more elegant way so this happens automatically?</p>
  
  <p><em>Edit2:</em> The ajax page is generated by php. I tried several things now to create the value of b, all result in JSON parse error on the page:</p>
  
  <pre><code>  $b = 'hello "kitty"';      
  
    // no 1:
    //$b = str_replace('"',"\x22",$b);
  
    // or no 2:
    // $b = addslashes($b);  
  
    // or no 3: 
    $b = str_replace('"','\"',$b);
  
    echo '{ "a" : "1", "b" : "' . $b . '"}';
  </code></pre>
  
  <p><em>Edit3:</em> This solution finally works:</p>
  
  <pre><code>$b = 'hello "kitty"';      
  $b = str_replace('"','\\"',$b); 
  echo '{ "a" : "1", "b" : "' . $b . '"}';
  </code></pre>