Created
December 22, 2014 21:50
-
-
Save jdherman/43c1ab6aa4d3b9ca5f44 to your computer and use it in GitHub Desktop.
convert BSON to valid json, then parse it in python
This file contains hidden or 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
#!/bin/bash | |
bsondump database.bson > database.json | |
# replace ObjectId("50f330869178b31dde000001") | |
# with just the string | |
sed -re 's/ObjectId\((.*)\)/\1/g' database.json > test.json | |
# then in python | |
import json | |
from pprint import pprint | |
data = [] | |
ct = 0 | |
with open('database.json') as f: | |
for line in f: | |
try: | |
data.append(json.loads(line)) | |
except: | |
pass | |
pprint(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment