title: JavaScript raises SyntaxError with data rendered in Jinja template
body: <p>I am trying to pass data as JSON from a Flask route to a Jinja template rendering JavaScript.  I want to iterate over the data using JavaScript.  The browser shows <code>SyntaxError: Unexpected token '&amp;'. Expected a property name.</code> when <code>JSON.parse</code> is called on the rendered data.  How do I use rendered JSON data in JavaScript?</p>
  
  <pre class="lang-javascript prettyprint-override"><code>var obj = JSON.parse({{ data }})
  for (i in obj){
     document.write(obj[i].text + "&lt;br /&gt;");
  }
  </code></pre>
  
  <pre class="lang-python prettyprint-override"><code>def get_nodes(node):
      d = {}
      if node == "Root":
          d["text"] = node
      else:
          d["text"] = node.name
  
      getchildren = get_children(node)
      if getchildren:
          d["nodes"] = [get_nodes(child) for child in getchildren]
      return d
  
  tree = get_nodes("Root")
  return render_template("folder.html", data=tree)
  </code></pre>
  
  <p>If I just put <code>{{ data }}</code> in the HTML part, what I see looks correct.</p>
  
  <pre><code>{'text': 'Root', 'nodes': [{'text': u'Prosjekt3'}, {'text': u'Prosjekt4', 'nodes': [{'text': u'mappe8'}]}]}
  </code></pre>