Skip to content

Instantly share code, notes, and snippets.

@jdherman
Created December 22, 2014 21:50
Show Gist options
  • Save jdherman/43c1ab6aa4d3b9ca5f44 to your computer and use it in GitHub Desktop.
Save jdherman/43c1ab6aa4d3b9ca5f44 to your computer and use it in GitHub Desktop.
convert BSON to valid json, then parse it in python
#!/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