title: Create JSON file from MongoDB document using Python
body: <p>I am using MongoDB 3.4 and Python 2.7.  I have retrieved a document from the database and I can print it and the structure indicates it is a Python dictionary. I would like to write out the content of this document as a JSON file. When I create a simple dictionary like <code>d = {"one": 1, "two": 2}</code> I can then write it to a file using <code>json.dump(d, open("text.txt", 'w'))</code>
  However, if I replace d in the above code with the the document I retrieve from MongoDB I get the error </p>
  
  <blockquote>
    <p>ObjectId is not JSON serializable</p>
  </blockquote>
  
  <p>Suggestions?</p>