Python TypeError: datetime.datetime not JSON serializable while using Mongo
Writing by shivdev on Monday, 3 of November , 2014 at 6:18 pm
This post from stackoverflow.com explains it.
Basically, you will need to use the default=json_util.default argument as defined in the PyMongo Docs
So, while converting a date object in a dictionary to JSON
from bson import json_util import json json_str = json.dumps(anObject, default=json_util.default) print json_str
And while reading back the JSON string into a dictionary
from bson import json_util import json json.loads(json_str, object_hook=json_util.object_hook)
Leave a comment
Category: Python
- Add this post to
- Del.icio.us -
- Digg -
- -
- Tweet -
-
-
No comments yet.
You must be logged in to post a comment.