title: JSON parse - single quote inside name
body: <p>In Django template I have printed out data like this:</p>
  
  <pre><code>P.place = '{{place.json|safe}}';
  </code></pre>
  
  <p>Then in JavaScript file I'm paring it like that:</p>
  
  <pre><code>place = JSON.parse(P.place);
  </code></pre>
  
  <p>Everything is fine for data like that:</p>
  
  <pre><code>{"category": "Cars", "name": "Z"}
  </code></pre>
  
  <p>Because string looks like that:</p>
  
  <pre><code>P.place = '{"category": "Cars", "name": "Z"}'
  </code></pre>
  
  <p>So, I can parse it using JSON.parse method witch accept strings as input.</p>
  
  <p>Problem is when I get data like that:</p>
  
  <pre><code>{"category": "Cars", "name": "Wojtek's Z"}
  </code></pre>
  
  <p>Because than input string for JSON parser looks like that:</p>
  
  <pre><code>'{"category": "Cars", "name": "Wojtek'
  </code></pre>
  
  <p>I cannot escape single quote inside JSON string, because then JSON string become invalid. From the same reason I cannot replace surrounding quotes by double and escape double quotes inside JSON string.</p>
  
  <p>My solution looks like that:</p>
  
  <p>In HTML template:</p>
  
  <pre><code>P.place = {{place.json|safe}};
  </code></pre>
  
  <p>Then in JavaScript</p>
  
  <pre><code>var place = JSON.stringify(P.place);
  place = JSON.parse(place);
  </code></pre>
  
  <p>It works, but it is not optimal solution IMHO.</p>
  
  <p>How to solve this problem in more cleaver way?</p>