Database Document Standard.bsonMIME: application/bson

BSON Format Specification: Binary JSON, MongoDB Storage & Data Traversals

Understand binary serialized document storage: fast traversal length prefixes, raw date/binary types, and client-side conversion.

BSON (Binary JSON) is a binary-encoded serialization format for JSON-like documents, primarily utilized as the internal storage and wire protocol format of MongoDB. While JSON is human-readable and text-based, BSON is engineered for machine efficiency—incorporating explicit 4-byte length prefixes for rapid byte skipping, ordered key-value pairs, and extended data types unavailable in standard JSON (such as 64-bit integers, precise timestamps, regex, and raw binary byte arrays).

Format Specification & Header Signature

Core file signatures, developer metadata, and standard RFC specifications:

Magic Bytes (Hex Signature)Prefix length (4-byte little-endian integer)
MIME Media Typeapplication/bson
Standard / SpecificationBSON Specification Version 1.1
Initial Developer / OrganizationMongoDB Inc. (2009)
Serialization EncodingLittle-Endian Binary Data
Extended Typesint32, int64, double, Date, Timestamp, BinData, ObjectId
Traversal OptimizationExplicit 4-byte total document length prefix
Text EncodingNull-terminated C-strings and UTF-8 string chunks

Operating System & Browser Compatibility Matrix

Where .bson is natively supported without third-party codecs:

Platform / EnvironmentNative SupportImplementation Notes
Cross-PlatformSupportedSupported across all programming languages via official MongoDB and BSON drivers.
Web BrowsersSupportedDecoded in browser memory via WebAssembly or standalone JS libraries (bson-js).

Advantages of Binary JSON

  • •Ultra-fast document traversal without parsing intermediate object properties.
  • •Native support for binary data (BinData) without 33% Base64 text inflation.
  • •Distinguishes between 32-bit integers, 64-bit long integers, and IEEE 754 doubles.
  • •Universal database wire protocol standard for document-oriented database systems.

Limitations & Trade-Offs

  • •Not human-readable in standard text editors without hex or JSON decoders.
  • •Slightly larger storage footprint than compressed Protobuf or MessagePack.

Length-Prefixed Element Architecture

Every BSON document begins with a 4-byte signed integer representing total document size in bytes. Each field begins with a 1-byte type code (e.g. \x02 for UTF-8 String, \x09 for UTC DateTime), followed by a null-terminated field name.

Because strings and nested objects include their exact byte length up front, search engines can skip unrequested sub-documents in O(1) time without reading inner bytes.

Frequently Asked Questions about Binary JSON

Is BSON smaller than JSON?

In some cases BSON is slightly larger than JSON due to field name duplication and explicit length headers, but BSON is drastically faster for computers to traverse and parse.

Can I convert BSON to JSON client-side?

Yes! Browser libraries can parse BSON byte arrays and serialize them into standard human-readable JSON in milliseconds.