Last active
May 14, 2018 05:11
-
-
Save soaxelbrooke/bdf8d5026fe32b6f6406 to your computer and use it in GitHub Desktop.
Decode mongo JSON in Python... with eval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It's not pretty, but it get's the job done. JSON is valid Python, so you can eval it, | |
# provided that you have the proper names in scope, like ObjectId and ISODate | |
from dateutil import parser | |
NumberLong = int | |
ObjectId = str | |
false = False | |
true = True | |
null = None | |
ISODate = parser.parse | |
lines = ['{"_id" : ObjectId("5539bae79a29809df4008265"), "created_at" : ISODate("2015-04-24T03:39:19.058Z")}', | |
'{"_id" : ObjectId("5539bae79a29809df4001953"), "created_at" : ISODate("2015-04-24T03:40:01.042Z")}'] | |
docs = [eval(line) for line in lines] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment