BSON Converter
Convert between JSON and BSON (binary JSON, MongoDB's wire format).
Overview
The BSON converter round-trips between JSON text and BSON's binary representation. Paste JSON to get hex-encoded BSON bytes, or paste BSON (in hex or base64) to recover the JSON document MongoDB sees over the wire.
It's useful when debugging a driver, inspecting a captured packet, or building a synthetic test fixture for a MongoDB integration. Backend developers and database administrators reach for a bson decoder when they need to know exactly what bytes leave the application before the server parses them.
How it works
BSON is a length-prefixed binary serialization for JSON-like documents, defined by the MongoDB team. Each document begins with a little-endian int32 length, followed by typed elements: each element is a one-byte type tag, a NUL-terminated key, and a type-specific payload. Strings carry their own length prefix, embedded documents are recursive BSON, and arrays are documents with stringified integer keys.
Extended types like ObjectId, Date, Binary, and Decimal128 have no direct JSON equivalent, so the converter renders them in the MongoDB Extended JSON v2 form ({"$oid":"..."}, {"$date":"..."}) for lossless round-tripping.
Examples
JSON in: {"hello":"world"}
BSON out: 16000000 02 68656c6c6f00 06000000 776f726c6400 00
JSON in: {"_id":{"$oid":"507f1f77bcf86cd799439011"}}
BSON out: 16000000 07 5f696400 507f1f77bcf86cd799439011 00
BSON in (hex): 0b00000010 6100 01000000 00
JSON out: {"a":1}
FAQ
What's the difference between BSON and JSON?
BSON adds binary types (ObjectId, Date, Binary, Decimal128), is length-prefixed for fast skipping, and uses fixed-width integers instead of arbitrary-precision numbers. It's not human-readable, but parsing is faster than ASCII JSON.
Does it support Decimal128 and Long?
Yes. Decimal128 is parsed and emitted using the IEEE 754-2008 decimal floating point encoding; 64-bit Long values are preserved exactly via {"$numberLong":"..."}.
Can I paste raw bytes from a packet capture?
Hex and base64 are both accepted. Strip MongoDB wire-protocol headers (opcodes, request IDs) first — the converter expects a single BSON document, not a full OP_INSERT envelope.