title: json.dump unable to serialize a dictionary containing a list in python
body: <p>I have this part <code>[{'scenariotestinputid': 1, 'scenarioid_id': 1, 'testinputid_id': 1}]</code> inside a python dictionary called result. When I call json.dumps(result), I get a TypeError saying that [{'scenariotestinputid': 1, 'scenarioid_id': 1, 'testinputid_id': 1}] is not JSON serializable. Can anyone explain why?</p>
  
  <p>Edit1: The complete "result" dictionary content is:  </p>
  
  <pre><code>result: {'scenarios': [{'inputs': [{'scenariotestinputid': 1, 'scenarioid_    id': 1, 'testinputid_id': 1}], 'scenarioid': 1, 'scenarioname': u'Default Scenario', 'testid_id': 1, 'isdefault': 1}, {'inputs': [], 'scenarioid': 2, 'scenarioname': u'Scenario-1', 'testid_id': 1, 'isdefault': 0}], 'status': 'success'}
  </code></pre>
  
  <p>The code I'm using is:  </p>
  
  <pre><code>if x == y:
      scenarios_list = Scenario.objects.filter(testid=testcase).order_by("scenarioname")
      scenarios_dict_list = []
      for scenario in scenarios_list:                                            
          scenario_inputs = scenario.scenariotestinput_set.values()
          scenario_dict = scenario.__dict__
          del scenario_dict['_state']
          scenario_dict['inputs'] = scenario_inputs            
          scenarios_dict_list.append(scenario_dict)
          result['scenarios'] = scenarios_dict_list
  result['status'] = "success"
  return HttpResponse(json.dumps(result), content_type="application/json")
  </code></pre>
  
  <p>inside a function  </p>
  
  <p>Edit2: The traceback is as follows:</p>
  
  <pre><code>(Pdb) 
  &gt; /opt/my_apps/cpr_proj/cpr/views.py(512)set_benchmark_metrics_dispatcher()
  -&gt; return HttpResponse(json.dumps(result), content_type="application/json")
  (Pdb) 
  TypeError: TypeErro...izable",)
  &gt; /opt/my_apps/cpr_proj/cpr/views.py(512)set_benchmark_metrics_dispatcher()
  -&gt; return HttpResponse(json.dumps(result), content_type="application/json")
  (Pdb) bt
    /opt/Python-2.7.3/Lib/threading.py(524)__bootstrap()
  -&gt; self.__bootstrap_inner()
    /opt/Python-2.7.3/Lib/threading.py(551)__bootstrap_inner()
  -&gt; self.run()
    /opt/Python-2.7.3/Lib/threading.py(504)run()
  -&gt; self.__target(*self.__args, **self.__kwargs)
    /opt/Python-2.7.3/Lib/SocketServer.py(582)process_request_thread()
  -&gt; self.finish_request(request, client_address)
    /opt/Python-2.7.3/Lib/SocketServer.py(323)finish_request()
  -&gt; self.RequestHandlerClass(request, client_address, self)
    /usr/local/lib/python2.7/site-packages/django/core/servers/basehttp.py(139)__init__()
  -&gt; super(WSGIRequestHandler, self).__init__(*args, **kwargs)
    /opt/Python-2.7.3/Lib/SocketServer.py(638)__init__()
  -&gt; self.handle()
    /opt/Python-2.7.3/Lib/wsgiref/simple_server.py(124)handle()
  -&gt; handler.run(self.server.get_app())
    /opt/Python-2.7.3/Lib/wsgiref/handlers.py(85)run()
  -&gt; self.result = application(self.environ, self.start_response)
    /usr/local/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py(67)__call__()
  -&gt; return self.application(environ, start_response)
    /usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py(241)__call__()
  -&gt; response = self.get_response(request)
    /usr/local/lib/python2.7/site-packages/django/core/handlers/base.py(111)get_response()
  -&gt; response = callback(request, *callback_args, **callback_kwargs)
  &gt; /opt/my_apps/cpr_proj/cpr/views.py(512)set_benchmark_metrics_dispatcher()
  -&gt; return HttpResponse(json.dumps(result), content_type="application/json")
    /opt/Python-2.7.3/Lib/json/__init__.py(231)dumps()
  -&gt; return _default_encoder.encode(obj)
    /opt/Python-2.7.3/Lib/json/encoder.py(201)encode()
  -&gt; chunks = self.iterencode(o, _one_shot=True)
    /opt/Python-2.7.3/Lib/json/encoder.py(264)iterencode()
  -&gt; return _iterencode(o, 0)
    /opt/Python-2.7.3/Lib/json/encoder.py(178)default()
  -&gt; raise TypeError(repr(o) + " is not JSON serializable")
  </code></pre>