title: jQuery, AJAX post Javascript array with JSON
body: <p>I have a Javascript variable which is an array (I push strings into it) and I have to send that list back to the server through an AJAX jQuery.POST() method:</p>
  
  <pre><code>var user_list = new Array();
  user_list.push("42");
  var data = { user_list: JSON.stringify(user_list)};
  $.post('/accounts/ajax/user_verification/', data)
      .done( my_cb );
  </code></pre>
  
  <p>In the server, I am running Django and try to decode the POST request with the following view:</p>
  
  <pre><code>@login_required
  def user_verification(request):
  
      if not request.POST.has_key('user_list'):
          print (__name__ + ', user_verification, raising BadRequest.')
          raise Exception("'user_list' not found as a POST parameter.")
  
      value = unicode(request.POST['user_list'])
      print (__name__ + ', value, v = ' + value)
      user_list = json.loads(request.body) 
  </code></pre>
  
  <p>I get the following output and posterior exception thrown by " json.loads(request.body) ":</p>
  
  <pre><code>accounts.ajax, value, v = ["42"]
  ValueError: No JSON object could be decoded
  </code></pre>
  
  <p>Isn't ["42"] a valid JSON array definition with a single element?</p>