title: Stream to JSON file using yield
body: <p>I have a function that read a file that reads chunks and return the following after every iteration. </p>
  
  <pre><code>def foo_now():
      for file in all_files:
          key_id, final_text = readChunk(file)
          yield {
              key_id : {
                  'desc': final_text
              }
          }
  </code></pre>
  
  <p>Ealier I was storing all these returned dictionaries into one single dictionary and them dumping the whole dictionary into a JSON file using: </p>
  
  <pre><code>def foo_earlier():
      temp_dict = dict()
      for file in all_files:
          key_id, final_text = readChunk(file)
          temp_dict.update({key_id : {'desc': final_text}})
      return temp_dict
  
  def saveJSON(filename, data):
      with open(filename, 'wb') as outfile:
          json.dump(data, outfile)
      print "Data saved in " + filename
  
  saveJSON("file.json", foo_earlier())
  </code></pre>
  
  <p>But now I want to dump each dictionary one by one as it is read from the file using <code>foo_now()</code>. How should I do that?</p>