title: Django/JS: json.dumps and parse.json
body: <p>I'm no programmer, so I can't go to source code of Django or Jquery and figure out how and why these function don't return what I want from them, because I simply wouldn't understand the source code.</p>
  
  <p>I do one little project for myself and here's my confusion about json part:
  here's my django/python function:</p>
  
  <pre><code>def searchPatients(request):
      patients = Patients.objects.filter(KeyName__icontains=request.POST.get('KeyName'))
      response = []
      for patient in patients:
          tmpvar = {}
          tmpvar = { 'Name1':patient.Name1, 'Name2':patient.Name2 }
          response.append(tmpvar)
      return HttpResponse(json.dumps(response), content_type="application/json")
  </code></pre>
  
  <p>I checked in shell, json.dumps(response) gave me this:</p>
  
  <pre><code>'[{"Name2": "TestName2", "Name1": "TestName1"}, {"Name2": "TempName2", "Name1": "TempName1"}]'
  </code></pre>
  
  <p>Looks ok form me. And then I don't understand part starts. This is my JS/JQuery function:</p>
  
  <pre><code>input_newRecord_Search.keyup(function() {
      $.post('/edit/ajax_search_patients', { KeyName: $(this).val() }, function(data) {
          var patients = jQuery.parseJSON(data);
          for (var patient in patients) {
          $('#searchResults ul').append('&lt;li&gt;'+patients[patient].Name1+'&lt;/li&gt;&lt;li&gt;+'patients[patient].Name2+'&lt;/li&gt;');
          };
      }, "json");
  });
  </code></pre>
  
  <p>I get an error: "SyntaxError: JSON.parse: unexpected character".
  I checked what data jquery gets from server: console.log(data):</p>
  
  <pre><code>[{Name2: "TestName2", Name1: "TestName1"}, {Name2: "TempName2", Name1: "TempName1"}]
  </code></pre>
  
  <p>So, as far as I know JSON syntax looks like - {"key":"value"} and I'm missing quotes on key field. And I don't understand why I'm missing them. I can put them manually through regex, for instance, but I don't think it's the right way. And using regex I can parse my entire data without need of jQuery.parseJSON(), but again I want to use jQuery function - after all it was made exactly for this purpose.
  Can anyone help me with this one?</p>