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.
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 Type | application/bson |
| Standard / Specification | BSON Specification Version 1.1 |
| Initial Developer / Organization | MongoDB Inc. (2009) |
| Serialization Encoding | Little-Endian Binary Data |
| Extended Types | int32, int64, double, Date, Timestamp, BinData, ObjectId |
| Traversal Optimization | Explicit 4-byte total document length prefix |
| Text Encoding | Null-terminated C-strings and UTF-8 string chunks |
Operating System & Browser Compatibility Matrix
Where .bson is natively supported without third-party codecs:
| Platform / Environment | Native Support | Implementation Notes |
|---|---|---|
| Cross-Platform | Supported | Supported across all programming languages via official MongoDB and BSON drivers. |
| Web Browsers | Supported | Decoded 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.
Client-Side Tools for Binary JSON (.bson)
Convert, optimize, or inspect .bson files directly inside your browser with zero server uploads:
JSON Formatter & Validator (Beautify & Minify)
Clean up messy API responses, fix syntax glitches, and compress JSON payloads directly in your browser.
Base64 Encoder & Decoder (Text & Images)
Convert binary images and strings into Base64 format for web embeds, CSS inlining, and data transmission.
CSV to JSON & JSON to CSV Online Converter
Two-way in-browser data transformer for developers and data analysts. Automatic number/boolean casting with zero server uploads.
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.