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
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.
- uuidbson depends on itGenerates and parses RFC‑4122/9562 UUIDs (v1‑v8) for Dart.
- fixnumbson depends on itProvides 32‑ and 64‑bit signed fixed‑width integer types for Dart.
- decimalbson depends on itArbitrary-precision decimal arithmetic for Dart
- rationalbson depends on itAllows you to deal with rational numbers in Dart.
- mongo_dartBuilt on bsonMongoDB driver implemented in pure Dart for server-side applications.
- shelf_easyBuilt on bsonLightweight framework with a JSON model generator, database operator, and web/WebSocket server/client.