Skip to content

Instantly share code, notes, and snippets.

View adiabatic's full-sized avatar

adiabatic

View GitHub Profile
@tedsparc
tedsparc / bson2json.rb
Created February 8, 2012 00:21
Easily convert a MongoDB BSON file to JSON with Ruby
#!/usr/bin/ruby
# This script acts as a command-line filter to convert a BSON file (such as from mongodump) to an equivalent JSON file
# The resulting JSON file will be an array of hashes
# Any binary values from the BSON file are converted to base64 (such as Mongo's _id fields)
# I originally wrote this script so that Mongo files can be easily used with jsawk for
# offline data processing -- https://github.com/micha/jsawk
#
# To invoke, assuming mycollection.bson is a file from mongodump:
# ruby bson2json.rb < mycollection.bson > mycollection.json