Use bson's JSON util to handle ObjectIds in a JSON context