title: Object of type 'ObjectID' is not JSON serializable
body: <p>I am having what appears to be a common problem but so far I can't see a solution that applies to me.  I think I'm just missing something small but I've broken down to ask for help.  I am trying to get json output using flask and pymongo.</p>
  
  <p>here is the object in the console using print(results): </p>
  
  <pre><code>[{'_id': ObjectId('598b5de38161a821188f1a7c'), 'first name': 'first name', 'last Name': 'last name'}]
  </code></pre>
  
  <p>when I try to return on that I get the error:
  TypeError: Object of type 'ObjectId' is not JSON serializable</p>
  
  <p>class Contacts(Resource):</p>
  
  <pre><code>def get(self):
      results =[]
      connect = MongoClient("&lt;REMOVED&gt;")
      db = connect['&lt;REMOVED&gt;']
      collection = db['contact']
      contacts = collection.find()
  
      if collection:
          number_of_contacts = collection.count()
          for document in contacts:
              results.append(document)
          print(results)
          return {'results': results, 'count': number_of_contacts}
  </code></pre>
  
  <p>I've tried the bson.json_util suggestions.  It did clear the serializable error by double encoding my json object.  Seems like that isn't a good solution for what I'm doing.</p>