🧬

BSON / MessagePack Decoder

Decode BSON (MongoDB) and MessagePack binary payloads into readable JSON. Upload a file or paste a hex string and get a fully highlighted, formatted JSON output ready for inspection or download.

BSON / MessagePack Decoder

Decode BSON (MongoDB) and MessagePack binary payloads into readable, formatted JSON.

How to Use the BSON and MessagePack Decoder

You have a binary payload from MongoDB or a MessagePack-based API and need to inspect its contents as readable JSON. Paste a hex-encoded binary string into the input area or upload a raw binary file, then click Decode. The tool automatically detects whether the input is BSON or MessagePack and displays the decoded data as syntax-highlighted JSON. No binary data ever leaves your browser.

MongoDB document debugging

A database developer extracts a BSON document from a MongoDB collection, converts it to hex using MongoDB tools, and pastes it into the decoder to inspect the full document structure. This is useful for diagnosing serialisation issues, validating schema migrations, or auditing document contents in a read-only environment.

MessagePack API payload inspection

A backend developer consuming a MessagePack-based API captures the raw binary response and decodes it to JSON for inspection. This verifies that server-side serialisation is producing the expected structure and that all fields are correctly typed.

Binary format education

A developer learning about binary serialisation formats uses the sample payloads to see how BSON and MessagePack represent the same data differently. The decoded JSON output reveals the type system differences between the two formats.

Log file binary data extraction

An engineer investigating a production issue finds binary-encoded data embedded in application logs. Copying the hex string from the log and pasting it into the decoder reveals the structured data without needing to set up a local MongoDB instance or install MessagePack libraries.

How the BSON and MessagePack Decoder Works

Both decoders are implemented as lightweight, zero-dependency JavaScript functions that operate on Uint8Array buffers. The hex input is first converted to bytes using a simple hex-to-byte conversion, stripping whitespace and validating even-length constraints. The tool then auto-detects the format and runs the appropriate decoder.

BSON Decoder

The BSON decoder walks the binary document structure sequentially. It reads the 4-byte document size header (little-endian int32), then iterates through elements where each element consists of a 1-byte type tag, a null-terminated C-string field name, and a type-specific value. Supported types include double, UTF-8 string, embedded document, array, binary data, ObjectId, boolean, UTC datetime, null, 32-bit integer, and 64-bit integer. The decoder terminates when it encounters the null byte marking the end of the document.

MessagePack Decoder

The MessagePack decoder reads the binary stream using a format-first approach where the first byte of each value determines both the type and the byte length. Positive fixints encode small integers in a single byte. The decoder handles all standard MessagePack formats including nil, booleans, 32-bit and 64-bit floats, 8/16/32-bit integers, variable-length strings, arrays, and maps. The auto-detection compares the first 4 bytes against the total byte length: if they match and the value is at least 5, the input is decoded as BSON.

Frequently Asked Questions

How do I convert a BSON file to hex for the decoder?

Use the file upload mode to load a .bson file directly, or convert to hex using command-line tools. On Linux or macOS, use xxd -p file.bson. In PowerShell, use Format-Hex file.bson. On Windows, use certutil -encodehex file.bson output.txt. Paste the resulting hex string into the hex input field if you prefer the paste workflow.

Does the decoder output MongoDB Extended JSON?

No. The decoder outputs standard JSON, not MongoDB Extended JSON format. BSON-specific types like ObjectId are decoded to their closest standard JSON representation, appearing as string literals. Date values are output as ISO 8601 strings. This keeps the output parsable by any standard JSON library without requiring MongoDB-specific parsing.

What is the file size limit for decoding?

There is no hard-coded limit, but very large files over 10 MB may be slow to decode due to single-threaded JavaScript execution. For hex input, textarea performance degrades with very long strings, so use file upload mode for large payloads. Files up to a few megabytes decode in under a second on modern hardware.

Can this tool encode JSON to BSON or MessagePack?

This tool is decode-only. Encoding from JSON to BSON or MessagePack requires building binary structures with correct type markers, byte ordering, and length prefixes, which is a substantially different implementation. If you need encoding, consider using libraries like bson in Node.js or msgpack in your target language.

How reliable is the BSON vs MessagePack auto-detection?

The auto-detection compares the first 4 bytes interpreted as a little-endian int32 against the total byte length. BSON documents always start with their exact document size, so a match reliably identifies BSON. MessagePack payloads very rarely have a first 4-byte value that coincides with the total byte length, making the heuristic robust in practice for real-world data.

bsonmessagepackbinarydecodemongodbserialise

More Tools You Might Like

πŸ”‘JWT Debugger
πŸ—„οΈSQL to NoSQL Query Converter
πŸ“±QR Code Generator & Scanner
πŸ“Word Counter
🟦CSS Flexbox & Grid Sandbox
πŸ”·JSON to TypeScript Generator