title: Pass JSON data in Django context
body: <p>Normally, if I want to return JSON data from a Django view, I can use a <a href="https://docs.djangoproject.com/en/2.0/ref/request-response/#jsonresponse-objects" rel="nofollow noreferrer">JsonResponse</a> like so:</p>
  
  <pre><code>from django.http import JsonResponse
  
  def my_view(request):
      return JsonResponse({'my_key': 'my_value'})
  </code></pre>
  
  <p>That data is sent to the frontend as a JavaScript object that I can immediately use.</p>
  
  <p>I'd like that same ease of use added to the context of a view, like so:</p>
  
  <pre><code>class WebsiteView(TemplateView):
      template_name = 'index.html'
  
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
          context['my_var'] = {'my_key': 'my_value'}
          return context
  </code></pre>
  
  <p>However, rendering the template with <code>{{ my_var }}</code> gives:</p>
  
  <pre><code>{&amp;quot;my_key&amp;quot;: &amp;quot;my_value&amp;quot;}
  </code></pre>
  
  <p>Ultimately, what I want is for <code>{{ my_var }}</code> to return the plain string rather than the HTML encoded version:</p>
  
  <pre><code>{"my_key": "my_value"}
  </code></pre>
  
  <p>This way, I can easily load it into a JavaScript object with <code>JSON.parse('{{ my_var }}')</code>.</p>
  
  <p>I know that one way to achieve this is by <a href="https://stackoverflow.com/questions/1912501/unescape-html-entities-in-javascript">manually unescaping the HTML entities</a>, but I was wondering if there was a better way to do this.</p>