BSON to JSON Converter
Convert BSON binary files to readable JSON online. Full BSON spec parser with drag-and-drop upload, hex input, syntax highlighting, and download.
About
BSON (Binary JSON) is a binary-encoded serialization format used primarily by MongoDB to store documents and for remote procedure calls. Its binary nature makes it unreadable without proper decoding. A single misinterpreted byte offset corrupts the entire downstream parse, producing silent data errors that propagate through ETL pipelines. This tool implements the full BSON specification (v1.1) as defined at bsonspec.org, decoding all 19 element types including ObjectId, Int64 via BigInt, Decimal128, UTC datetime, regex, and nested subdocuments. It parses raw binary data byte-by-byte using little-endian reads with strict bounds checking.
Limitation: Decimal128 values are rendered as hex strings because IEEE 754 128-bit float precision cannot be fully represented in JavaScript's native 64-bit doubles. Documents exceeding 16 MB (MongoDB's default max) are accepted but may cause slower parsing in the browser. The parser assumes well-formed BSON. Malformed or truncated documents will produce a descriptive error at the exact byte offset of failure.
Formulas
A BSON document is a linear sequence of bytes. Parsing begins by reading the total document size as a 32-bit little-endian integer at offset 0. Each element follows the pattern:
where type is a single byte identifying the data type, name is a null-terminated UTF-8 string (the field key), and payload varies per type. Strings use length-prefixed encoding:
where len includes the null terminator. Int64 values are read as two 32-bit halves and combined:
where lo is the unsigned lower 32 bits and hi is the signed upper 32 bits. This uses JavaScript BigInt for lossless representation. The document terminates with a 0x00 byte. The parser validates that the consumed byte count matches the declared document size.
Reference Data
| Type ID | BSON Type | JSON Representation | Size (bytes) | Notes |
|---|---|---|---|---|
| 0x01 | Double | Number | 8 | IEEE 754 64-bit float |
| 0x02 | String | String | 4 + n + 1 | UTF-8 encoded, length-prefixed |
| 0x03 | Document | Object | Variable | Embedded BSON document |
| 0x04 | Array | Array | Variable | Keys are "0", "1", "2"… |
| 0x05 | Binary | Base64 string | 5 + n | Subtype byte included |
| 0x06 | Undefined | null | 0 | Deprecated in BSON spec |
| 0x07 | ObjectId | Hex string (24 chars) | 12 | Timestamp + machine + counter |
| 0x08 | Boolean | true / false | 1 | 0x00 = false, 0x01 = true |
| 0x09 | UTC Datetime | ISO 8601 string | 8 | Milliseconds since Unix epoch |
| 0x0A | Null | null | 0 | No payload |
| 0x0B | Regex | {"pattern": ..., "flags": ...} | Variable | Two cstrings: pattern + options |
| 0x0D | JavaScript Code | String | 4 + n + 1 | UTF-8 JS source code |
| 0x0E | Symbol | String | 4 + n + 1 | Deprecated, treated as string |
| 0x0F | Code w/ Scope | {"code": ..., "scope": ...} | Variable | Deprecated in MongoDB 4.4+ |
| 0x10 | Int32 | Number | 4 | Signed 32-bit integer, little-endian |
| 0x11 | Timestamp | {"t": ..., "i": ...} | 8 | Internal MongoDB replication timestamp |
| 0x12 | Int64 | String (BigInt) | 8 | Signed 64-bit, exceeds Number.MAX_SAFE_INTEGER |
| 0x13 | Decimal128 | Hex string | 16 | IEEE 754 128-bit decimal |
| 0xFF | Min Key | {"$minKey": 1} | 0 | Internal type, compares less than all |
| 0x7F | Max Key | {"$maxKey": 1} | 0 | Internal type, compares greater than all |