TXT · Text & Data tools

BSON Decoder

Input encoding
Indent
Or load a file
Encoded bytes
Decoded
BSONformat0 Binput0lines out0chars out
Open the full binary format decoder with every format and the encoder

Shareable link

Settings are written to the URL as you change them. Nothing differs from the defaults yet.

Length first, little endian

A BSON document begins with a 4-byte length and ends with a null byte. Each element in between is a type byte, a null-terminated field name, then the value. Every integer in the format is little endian, which is why a BSON hex dump looks reversed next to a network protocol.

160000000268656c6c6f0006000000776f726c640000 is the standard example and decodes to {"hello": "world"}.

Types JSON does not have

An ObjectId is 12 bytes: a 4-byte timestamp, 5 random bytes, and a 3-byte counter. It renders here as hex rather than as a string, because the bytes are the identifier.

A UTC datetime is milliseconds since the epoch as a signed 64-bit integer, rendered as ISO 8601. A timestamp is a different type entirely, used internally by replication, and keeps its seconds and increment. Decimal128 is shown as raw hex, since converting it through a JavaScript number would defeat the point of using it.

Arrays are documents

BSON stores an array as a document whose keys are "0", "1", "2" and so on. The decoder turns those back into a JSON array, which is why the numeric field names do not appear in the output.

Frequently Asked Questions

Double, string, embedded document, array, binary with its subtype, ObjectId, boolean, UTC datetime, null, regex, JavaScript with and without scope, int32, int64, timestamp, decimal128, and the min and max keys.

A BSON document starts with its own total length as a little endian int32. If that number does not match the bytes present, the payload is truncated or the wrong slice was copied.

Hex or Base64 pasted into the input pane, or a .bson file loaded with the file picker.

Pages locked to one format

Full Binary Format Decoder tool

Explore Our Tools

Browse all tools