NEW
Also known as: Binary JSON
A binary-encoded serialization format for JSON-like documents commonly used by MongoDB.
DESCRIPTION
BSON encodes JSON-like documents in a binary form with explicit types such as dates and binary data. It prioritizes efficient traversal, encoding, and decoding for document databases. MongoDB uses BSON for storage and network transfer, enabling typed fields and indexed queries. Drivers convert between language-native types and BSON. Alternatives include JSON, CBOR, and MessagePack, each with different trade-offs in size, speed, and type richness.
ALTERNATIVE DEFINITIONS
Wikipedia
BSON is a computer data interchange format. It is a binary form for representing simple data structures and associative arrays (called documents in MongoDB).
Highlights document-oriented representation in MongoDB.
BSON Specification
BSON is a binary-encoded serialization of JSON-like documents.
Concise, specification-level definition of purpose.
RELATED TERMS
MongoDB MessagePack Data Schema Document Store NoSQL Serialization Extended JSON Binary Encoding
COMPETING TERMS
JSON Concise Binary Object Representation
RELATIONS
- Broader: Binary Encoding Serialization
KNOWLEDGE AREAS
Data Engineering Data Storage & Operations Data Integration & Interoperability
TARGET AUDIENCE
Software Developer Data Engineer Data Architect
EXTERNAL SOURCES
- Wikipedia - BSON
- BSON Specification - Official BSON specification
- MongoDB - BSON data types in MongoDB
TOP QUESTIONS
Why does MongoDB use BSON instead of JSON?
BSON supports additional data types and efficient traversal. It improves storage and query performance compared to plain text JSON while preserving a document model.
Category: Relevancy
How does BSON compare to JSON in size and speed?
BSON is binary and typically smaller for typed data, with faster parsing. However, for simple text-heavy payloads, compression and alternatives may change trade-offs.
Category: Alternatives
Is BSON human-readable?
No. BSON is binary and intended for machines. Tools can convert BSON to Extended JSON for readability and debugging.
Category: Misunderstanding
Can I use BSON outside MongoDB?
Yes, drivers and libraries exist for multiple languages. Still, adoption beyond MongoDB is limited compared to JSON or Protocol Buffers.
Category: Scope
What are common BSON pitfalls?
Using unsupported types across drivers and relying on floating-point for precise values can cause issues. Prefer Decimal128 for financial amounts.
Category: Mistakes
How does BSON handle dates?
BSON includes a native datetime type encoded as milliseconds since the epoch. Ensure timezone handling is consistent across applications.
Category: Concepts
What is Extended JSON in MongoDB?
Extended JSON provides a textual representation of BSON types, allowing lossless round trips between JSON and BSON.
Category: Concepts
How does BSON impact indexing performance?
Typed fields allow efficient indexes and comparisons. Proper field selection and type consistency are crucial for predictable performance.
Category: Best practices
What are alternatives to BSON for binary serialization?
Protocol Buffers, Avro, CBOR, and MessagePack are popular alternatives, each with different schemas, type systems, and tooling.
Category: Alternatives