title: Django: Reading Array of JSON objects from QueryDict
body: <p>How do I pass a composite JSON structure via AJAX call from JS and on the server side, read it as a "very similar" data structure in python?</p>
  
  <p>I understand that json formatting can be used (simplejson etc), but I somehow feel that the QueryDict itself is malformed or reformatted in my case?</p>
  
  <p>Example:</p>
  
  <p>When passing an array of JSON objects [{"id": 1},{"id": 2},{"id": 3}] via AJAX to Django view, the QueryDict gets formatted as: </p>
  
  <pre><code>POST:&lt;QueryDict: {u'json_data[0][id]': [u'1'], u'type': [u'clone'], 
  u'csrfmiddlewaretoken': [u'69bb3c434ced31ab301ede04bf491ec0'], 
  u'json_data[1][id]': [u'2'], u'json_data[2][id]': [u'3']}&gt;
  </code></pre>
  
  <p>How do I even iterate through the json_data?</p>
  
  <p>I want to get something like this instead:</p>
  
  <pre><code>POST:&lt;QueryDict: {u'json_data': [{u'id': [u'1']}, {u'id': [u'2']}, {u'id': [u'3']}]},
  u'csrfmiddlewaretoken': [u'69bb3c434ced31ab301ede04bf491ec0'], u'type': [u'clone']&gt;
  </code></pre>
  
  <p>So that I can access QueryDict as a dictionary and retrieve json_data as a list and process it in a certain order: maybe just iterate through them in sequential list order.
  Something like: </p>
  
  <pre><code>ret = request.POST
  for item in ret['json_data']:
      process(item['id'])
  </code></pre>
  
  <p>In fact the value that goes into process() could be another dictionary of key value pairs instead of just a number (1,2,3 etc)</p>
  
  <p><strong>Javascript:</strong></p>
  
  <pre><code>var test = [{"id": 1},{"id": 2},{"id": 3}];
  $.post(
      "/insert_tc",
      {
        json_data: test,
        "type": 'clone',
        "csrfmiddlewaretoken": $csrf_token
      },  
      function(json) {
          //CALLBACK
      },
      "json"
  );  
  </code></pre>
  
  <p><strong>views.py:</strong></p>
  
  <pre><code>def insert_tc(request):
      if request.method == 'POST':       
      ret = request.POST
      type = ret['type']
      list = ret.getlist(ret)
  </code></pre>
  
  <p>But list returns empty []</p>
  
  <p>I tried simplejson dumps, loads, items, get methods but none of them helped. </p>
  
  <p>I even tried jQuery.param( obj, true ), but that's not what I want (although somewhat close).</p>
  
  <p>Is there a different/better way to pass composite data structures back and forth Django &lt;-> JS via AJAX?</p>