title: How can I get Django to return JsonResponse with no extra quotes or quote escapes?
body: <p>Using Django 1.7, whenever I return the following bit of JsonResponse in a view:</p>
  
  <pre><code>from django.http import JsonResponse
  token = "1$aEJUhbdpO3cNrXUmFgvuR2SkXTP9="
  response = JsonResponse({"token": token})
  return response
  </code></pre>
  
  <p>I'm getting the following HTTP response from web browser/cURL:</p>
  
  <pre><code>"{\"token\": \"1$aEJUhbdpO3cNrXUmFgvuR2SkXTP9=\"}"
  </code></pre>
  
  <p>What I want, and what I had in Django 1.3 was this:</p>
  
  <pre><code>{"token": "1$aEJUhbdpO3cNrXUmFgvuR2SkXTP9="}
  </code></pre>
  
  <p>I have two mobile apps in production that rely on a private API using Django, and unfortunately they are expecting the second kind of response, with no extra quotes  (the quote that surround the entire JSON making it a string) and no quote escapes.</p>
  
  <p>My question is, is there some built-in way to force Django response to not escape a JSON response?</p>
  
  <p>I wrote the following middleware to do it, but...it seems like a really fragile brute force way of going about it:</p>
  
  <pre><code>class UnescapeJSON(object):
      def process_response(self, request, response):
          """
          Directly edit response object here, searching for and replacing terms
          in the html.
          """
          if re.search('^/api/.*', request.path):
              r = response.content
              r = r.replace('\\', '')
              r = r.lstrip('"')
              r = r.rstrip('"')
              response.content = r
          return response
  </code></pre>
  
  <p>So I'm hoping there is a smarter way.</p>
  
  <p>Backstory is I'm trying to update an old legacy code base from Django 1.3 to 1.8. I currently have it on 1.7 in my local dev environment. Django 1.3 returned the JSON the correct way, without extra quotes and backslashes.</p>
  
  <p>One nice thing about returning the JSON in this way:</p>
  
  <pre><code>{"token": "1$aEJUhbdpO3cNrXUmFgvuR2SkXTP9="}
  </code></pre>
  
  <p>...is that I'm using <code>jQuery.post({success:...})</code> to handle this JSON response, and it automatically runs <code>jQuery.parseJSON()</code> for me, turning it into a JSON object I can access with dot notation.</p>
  
  <p>I can't just fix string on the client side and re-run <code>parseJSON()</code> manually, because that would involve getting all my users to upgrade their mobile app.</p>
  
  <p>So I have to get JSON formatted as above, or my mobile API is effectively broken.</p>
  
  <p>One bit of info I should add. This API is using Django Piston :(. I'm using a 1.7x compatible version I found. It's not in the cards for me to swap in Django REST Framework right now. Believe me, I will as soon as feasibly possible.</p>