title: Flask-PyMongo - Object of type InsertOneResult is not JSON serializable
body: <p>i have an api and i am trying to store/post a user object using Flask-Pymongo.</p>
  
  <p>but, i get the following error</p>
  
  <blockquote>
    <p>File
    "/home/kay/.local/share/virtualenvs/server-iT4jZt3h/lib/python3.7/site-packages/flask/json/<strong>i│
    nit</strong>.py", line 321, in jsonify<br>
    │
        dumps(data, indent=indent, separators=separators) + '\n',                                        │   File
    "/home/kay/.local/share/virtualenvs/server-iT4jZt3h/lib/python3.7/site-packages/flask/json/<strong>i│
    nit</strong>.py", line 179, in dumps<br>
    │
        rv = _json.dumps(obj, **kwargs)                                                                  │   File "/usr/lib/python3.7/json/<strong>init</strong>.py", line 238, in dumps<br>
    │
        **kw).encode(obj)                                                                                │   File "/usr/lib/python3.7/json/encoder.py", line 201, in encode<br>
    │
        chunks = list(chunks)                                                                            │   File "/usr/lib/python3.7/json/encoder.py", line 438, in
    _iterencode                                │
        o = _default(o)                                                                                  │   File "/home/kay/link/server/src/run.py", line 18, in default<br>
    │
        return json.JSONEncoder.default(self, o)                                                         │   File "/usr/lib/python3.7/json/encoder.py", line 179, in default<br>
    │
        raise TypeError(f'Object of type {o.<strong>class</strong>.<strong>name</strong>} '                                        │ TypeError: Object of type InsertOneResult is not JSON serializable</p>
  </blockquote>
  
  <p><strong>app/users/resource.py</strong></p>
  
  <pre><code>from flask_restful import Resource
  from flask import jsonify, request
  from .repository import UsersRepository
  from db import mongo
  
  
  class UsersResource(Resource):
  
      def __init__(self):
  
          self.repository = UsersRepository()
  
      def get(self):
  
          data = {"Users": "Resource"}
          res = data, 200
          return res
  
      def post(self):
  
          req = request.get_json()
  
          user = {
              "email": req.get("email"),
              "password": req.get("password")
          }
  
          result = mongo.db.users.insert_one(user)
  
          return jsonify(result)
  </code></pre>
  
  <p><strong>run.py</strong></p>
  
  <pre><code>from flask import Flask
  from app import api_bp
  from db import mongo
  from bson.objectid import ObjectId
  import json
  import datetime
  import os
  
  class JSONEncoder(json.JSONEncoder):
  
      def default(self, o):
          if isinstance(o, ObjectId):
              return str(o)
          if isinstance(o, set):
              return list(o)
          if isinstance(o, datetime.datetime):
              return str(o)
          return json.JSONEncoder.default(self, o)
  
  
  
  def create_app(config_filename):
  
      app = Flask(__name__)
      app.config.from_object(config_filename)
      app.register_blueprint(api_bp, url_prefix='/api')
  
      mongo.init_app(app)
  
      app.json_encoder = JSONEncoder
  
      return app
  
  
  # def logger():
  
  
  # def database():
  
  
  if __name__ == "__main__":
      app = create_app("config")
      app.run(host='0.0.0.0', port=8080, debug=True)
  </code></pre>