title: Django: Parse JSON in my template using Javascript
body: <p>I have this in my view:</p>
  
  <pre><code>string_location = myaddress2
      geodata = []
      for place, (lat, lng) in g.geocode(string_location,exactly_one=False):
          geodata.append((place, (lat, lng)))
  
      geodata_results = len(geodata)
  
      data = {"geodata": geodata, "geodata_results":geodata_results }
      return render_to_response("business/business_view.html",
                                data, context_instance=RequestContext(request))
  </code></pre>
  
  <p>How would I "handle" / convert <em>geodata</em> into JSON and pass it to my template so that I can "loop" through it like an array? </p>
  
  <p>Am I right to think that I can do it this way? If not, then please suggest on a better solution.</p>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>var geodata = "[[&amp;quot;M. L. Quezon Street&amp;lt;br/&amp;gt;Mandaue City, Philippines&amp;quot;, [10.351381999999999, 123.923535]], [&amp;quot;Talamban&amp;lt;br/&amp;gt;Cebu City, Philippines&amp;quot;, [10.353527, 123.91352500000001]]]"; 
  </code></pre>
  
  <p>I think the JSON is not escaped? How do I escape special characters inside the json string?
  I keep getting a newline error. </p>
  
  <p>For PHP, I would json_encode() to fix this. Like in this post: <a href="https://stackoverflow.com/questions/168214/pass-a-php-string-to-a-javascript-variable-including-escaping-newlines">Pass a PHP string to a JavaScript variable (and escape newlines)</a> BUT how do I do that in Python/Django?</p>