Skip to content
pubscout

bson

5.0.8, released 10 months ago by an unverified publisher

BSON binary-encoded serialization library for Dart and EJSON support.

WASM-readyUnverified publisher
$ flutter pub add bson
Source repository

What it does

Allows conversion of Dart maps, EJSON representations, and objects using the BsonSerializable mixin into binary BSON representation and vice versa. Provides classes like BsonCodec, EjsonCodec, and ObjectCodec to handle serialization and deserialization.

AI-written summary of version 5.0.8, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to serialize and deserialize BSON data in Dart.
  • You are working with MongoDB or systems requiring EJSON compatibility.
  • You want to serialize custom Dart objects using a BsonSerializable mixin.

Skip it when

  • You only need standard JSON serialization (use built-in dart:convert or json_annotation instead).
  • You require complex schema-driven code generation without manual mixins.

Strengths

  • Supports full BSON type mapping including ObjectIds, Timestamps, and Decimals.
  • Provides EJSON version 2 support.
  • Includes support for object serialization via mixins.

Weaknesses

  • Breaking API changes introduced in major versions require migration effort.
  • Handling types properly in cross-platform targets like dart2js requires explicit wrapping for certain types like doubles.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
6

Add the dependency to pubspec.yaml and import the package.

var bsonBinary = BsonCodec.serialize(bsonDocument);
var result = BsonCodec.deserialize(bsonBinary);

Works with

Packages commonly used together with bson: ones it builds on, ones built on it, and its own family.