BSON Parser

BSON (Binary JSON) is the binary serialization format used by MongoDB to store documents. It extends JSON with additional types like ObjectId, Date, Binary, and Decimal128. This tool parses BSON files and displays the contents as JSON with type information.

Specifications

Common Use Cases

  • Inspect MongoDB dump files (.bson)
  • Debug BSON data in message queues or caches
  • Analyze MongoDB wire protocol captures
  • Convert BSON to JSON for external tools
  • Audit document structure and types

Features

  • Parse BSON binary files via drag-and-drop or file selection
  • Decode hex-encoded BSON data
  • Display all BSON types including ObjectId, Date, Binary, Regex, Decimal128
  • Convert to JSON with extended JSON notation
  • Show document metadata (size, field count, max depth)
  • List all ObjectIds and dates found in the document
  • Display binary field sizes and extension types
  • Hex viewer for raw binary inspection

Examples

Simple BSON Document

Try it →

A minimal BSON document with a single field: {"hello":"world"}

16 00 00 00 02 68 65 6c 6c 6f 00 06 00 00 00 77 6f 72 6c 64 00 00

Hex-Encoded BSON

Try it →

A BSON document with string, number, and boolean: {"name":"Alice","age":30,"active":true}

27 00 00 00 02 6e 61 6d 65 00 06 00 00 00 41 6c 69 63 65 00 10 61 67 65 00 1e 00 00 00 08 61 63 74 69 76 65 00 01 00

Tips

  • You can paste hex-encoded BSON data directly to parse it.
  • BSON files can be created with: mongoexport --collection=users --out=users.bson
  • ObjectIds contain a timestamp; extract with: new ObjectId().getTimestamp()
  • BSON supports more types than JSON: dates, binary, regex, and decimals.
  • The maximum BSON document size in MongoDB is 16MB.

Understanding BSON

BSON (Binary JSON) is the binary serialization format used internally by MongoDB to store and transmit documents. While JSON represents all data as strings, numbers, booleans, arrays, and objects, BSON extends this with additional types that databases need: ObjectId (a 12-byte unique identifier), Date (millisecond-precision timestamps), Binary (arbitrary byte arrays), Decimal128 (exact decimal arithmetic), and regular expressions.

BSON documents are length-prefixed, meaning each document and embedded document starts with a 4-byte size field. This allows parsers to skip over documents without fully decoding them, enabling efficient scanning and indexing. Each element is tagged with a type byte, followed by the field name as a C-string, followed by the value in a type-specific encoding.

MongoDB stores documents as BSON internally, transmits them over the wire protocol, and exports them with mongodump as .bson files. Understanding BSON is essential for debugging MongoDB applications, analyzing dump files, and working with the wire protocol. The extended JSON format provides a human-readable representation that preserves BSON type information.

BSON is not always smaller than JSON. Short strings and small numbers may actually be larger in BSON due to the type byte and length prefix overhead. BSON's advantage is not size but speed — the length-prefixed format enables fast traversal and the extended types provide native support for dates, binary data, and high-precision decimals without encoding conventions.

ObjectId is a 12-byte BSON type used as the default _id in MongoDB documents. It contains a 4-byte timestamp (seconds since epoch), 5 bytes of random value (unique per machine/process), and a 3-byte incrementing counter. This design ensures uniqueness across distributed servers without any coordination. The embedded timestamp means you can extract a document's creation time with ObjectId.getTimestamp().

MongoDB dump files (.bson) created by mongodump are raw BSON documents concatenated together. You can paste hex-encoded BSON data into this tool to parse individual documents. Alternatively, the bsondump utility (included with MongoDB Database Tools) can convert .bson files to JSON on the command line for bulk inspection.

← Back to all tools