BSON to JSON Converter

Decodes hex-encoded BSON (the binary document format MongoDB uses on the wire), doubles, strings, embedded documents, arrays, booleans, null, int32, and int64, back into a readable JSON document. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-24

Overview

Introduction

When you're debugging a MongoDB wire-protocol capture, a driver's encoder, or a BSON fixture, you often end up staring at a hex dump of bytes with no easy way to see what document it actually represents.

This tool decodes that hex-encoded BSON back into readable JSON directly in the browser, no MongoDB driver or server required.

What Is BSON to JSON Converter?

A BSON decoder that reads a hex-encoded byte sequence, its length-prefixed document structure, typed elements, and null terminator, and reconstructs the equivalent JSON value.

It decodes the same element types the site's JSON to BSON Converter produces: doubles, strings, embedded documents, arrays, booleans, null, int32, and int64.

How BSON to JSON Converter Works

The decoder first turns the hex text into raw bytes, then reads the leading 4-byte little-endian length prefix and walks each typed element in sequence, using each element's type byte to know how many following bytes to consume and how to interpret them.

Embedded documents and arrays are decoded by recursively applying the same document-reading logic, with array elements distinguished by their numeric string keys ("0", "1", ...) the way the BSON spec defines arrays.

When To Use BSON to JSON Converter

Use it when you have a BSON hex dump from a wire-protocol capture, driver test, or the JSON to BSON Converter and need to see what document it actually decodes to.

It's also useful for learning BSON's binary layout by pairing a hex dump with its decoded JSON side by side.

Features

Advantages

  • Decodes directly in the browser with no MongoDB driver or server needed.
  • Reports a specific error when the byte sequence is malformed rather than failing silently.
  • Accepts the exact hex format the companion JSON to BSON Converter produces, so the pair round-trips cleanly.

Limitations

  • Doesn't decode MongoDB extended types like ObjectId, Date, or Binary, since those have no direct JSON equivalent.
  • Expects a hex-encoded string, not a raw uploaded .bson binary file.

Examples

Decoding a small document

Input

2e 00 00 00 10 5f 69 64 00 01 00 00 00 02 6e 61 6d 65 00 0d 00 00 00 41 64 61 20 4c 6f 76 65 6c 61 63 65 00 08 61 63 74 69 76 65 00 01 00

Output

{
  "_id": 1,
  "name": "Ada Lovelace",
  "active": true
}

The int32 _id, string name, and boolean active elements are read in order and reassembled into a JSON object.

Invalid BSON

Input

2e 00 00 00 10 5f 69

Output

Invalid BSON: unexpected end of input while reading element

A hex string that's truncated mid-element is rejected with a description of what went wrong.

Best Practices & Notes

Best Practices

  • Use the exact hex output from JSON to BSON Converter when testing the pair, rather than hand-editing bytes, to avoid introducing an invalid length prefix.
  • Strip any non-hex formatting (like a 0x prefix per byte) before pasting, the decoder expects plain space-separated hex pairs.
  • Cross-check unexpected output against the BSON spec's type byte table when a document decodes but looks wrong.

Developer Notes

The decoder reads bytes with a DataView-backed cursor that advances by exactly the number of bytes each type consumes (4 for int32, 8 for double/int64, a length-prefixed run for strings), rather than regex-based parsing, since BSON's binary layout is fundamentally positional and has no textual delimiters to scan for.

BSON to JSON Converter Use Cases

  • Inspecting a BSON hex dump captured from MongoDB's wire protocol
  • Verifying that a driver or custom encoder produced spec-correct BSON bytes
  • Round-tripping a document through JSON to BSON Converter and back to confirm no data was lost

Common Mistakes

  • Pasting a raw binary .bson file's contents instead of its hex representation.
  • Expecting ObjectId or Date values to decode to something other than their raw byte representation, since those extended types aren't part of this decoder's scope.
  • Including formatting like 0x prefixes or commas between hex pairs, which will break parsing.

Tips

  • Pair with JSON to BSON Converter to round-trip a document and confirm both directions agree.
  • If a document fails to decode, check the length prefix first, an incorrect total length is the most common cause of a truncated read.

References

Frequently Asked Questions