title: MemoryError using json.dumps()
body: <p>I would like to know which one of <code>json.dump()</code> or <code>json.dumps()</code> are the most efficient when it comes to encoding a large array to json format.</p>
  
  <p>Can you please show me an example of using <code>json.dump()</code>?</p>
  
  <p>Actually I am making a Python CGI that gets large amount of data from a MySQL database using the ORM SQlAlchemy, and after some user triggered processing, I store the final output in an Array that I finally convert to Json.</p>
  
  <p>But when converting to JSON with : </p>
  
  <pre><code> print json.dumps({'success': True, 'data': data}) #data is my array
  </code></pre>
  
  <p>I get the following error: </p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/script/cgi/translate_parameters.py", line 617, in     &amp;lt;module&amp;gt;
  f.write(json.dumps(mytab,default=dthandler,indent=4))
    File "C:\Python27\lib\json\__init__.py", line 250, in dumps
      sort_keys=sort_keys, **kw).encode(obj)
    File "C:\Python27\lib\json\encoder.py", line 209, in encode
      chunks = list(chunks)
  MemoryError
  </code></pre>
  
  <p>So, my guess is using <code>json.dump()</code> to convert data by chunks. Any ideas on how to do this? </p>
  
  <p>Or other ideas besides using <code>json.dump()</code>?</p>