This is a simple clone of SilverStripe's JSON Data Formatter, modified to encode and decode BSON.