title: Right way to escape JSON data from django template
body: <p>I want to pass a dictionary from django view to a javascript file. The dictionary is built from a database populated by site users. What's the difference between these 2 methods in terms of security?</p>
  
  <ol>
  <li><p><code>var mydata = JSON.parse("{{mydata|escapejs}}");</code></p></li>
  <li><p><code>var mydata = {{ mydata|safe }};</code></p></li>
  </ol>
  
  <p>Further, the <a href="https://docs.djangoproject.com/en/dev/ref/templates/builtins/#escapejs" rel="nofollow">doc at django</a> says this for <code>escapejs</code> : <em>This does not make the string safe for use in HTML</em>. Could you show me an example of how it's unsafe &amp; how can I make it safe.</p>