JSON to BSON Converter
Paste JSON to view its BSON binary representation as a hex dump with size calculations
Paste any JSON object or array and get back a BSON-encoded hex dump with byte offsets, element counts, and a size comparison between the original JSON and the binary output. Useful for debugging MongoDB documents, testing custom drivers, or just seeing how BSON actually lays out your data at the byte level. And everything runs in your browser. Nothing gets uploaded.
How It Works
The tool parses your JSON, then walks through every key and value to produce BSON bytes — type markers, length prefixes, null-terminated C-strings for keys, and IEEE 754 doubles for numbers. The output is a hex dump with byte offsets on the left, so you can trace exactly where each field sits in the binary stream. A stats panel breaks down document size, element count, and how BSON compares to the original JSON in bytes.
Examples
Simple User Document
A basic MongoDB-style user record — the kind you’d store in a collection.
{"name":"Alice","age":29,"active":true}00000000: 2F 00 00 00 02 6E 61 6D
00000008: 65 00 06 00 00 00 41 6C
00000010: 69 63 65 00 01 61 67 65
...
BSON Size: 47 bytesNested Object with Array
Testing how BSON handles embedded documents and arrays — useful when you’re verifying subdocument encoding in a custom driver.
{"order":{"id":5012,"items":["pen","notebook"],"shipped":false}}Hex dump showing nested doc
with type 0x03 (embedded doc),
type 0x04 (array), and type
0x08 (boolean) markers.
BSON Size: ~95 bytesEmpty Document vs. Empty Array
Quick sanity check. An empty object {} and an empty array [] both encode to exactly 5 bytes in BSON — a 4-byte length prefix plus a null terminator. Good to know when you’re calculating payload sizes.
{}00000000: 05 00 00 00 00
BSON Size: 5 bytesWho Uses This
Debug MongoDB wire protocol messages and verify BSON encoding in custom drivers or ORMs.
Compare document sizes before and after schema changes to estimate storage impact.
Study binary encoding formats and see how text-based JSON translates to typed binary bytes.
Validate that API payloads serialize correctly by checking the raw BSON output against expected byte patterns.
Common Mistakes
BSON only encodes documents (objects) or arrays at the top level. Feeding in "hello" or 42 alone will throw an error. Wrap it: {"value": 42}.
For small documents with short strings, BSON is actually bigger. It adds length prefixes and type bytes. The efficiency gains show up with lots of numeric data or deeply nested structures — not tiny payloads.
JSON is strict. {'name': 'test',} isn’t valid — double quotes only, no trailing commas. The parser will reject it before BSON encoding even starts.
Technical Details
- Processing: 100% client-side — no server, no uploads
- Browser Support: Chrome, Firefox, Safari, Edge
- BSON Spec: Follows bsonspec.org for core types (string, double, boolean, null, document, array)
- Number Encoding: All JSON numbers stored as IEEE 754 double (8 bytes), matching MongoDB default behavior
- Max Input: Limited only by browser memory
Frequently Asked Questions
What is BSON and why does MongoDB use it?
BSON stands for Binary JSON. MongoDB chose it because the binary format allows fast field lookups without parsing the entire document — the length prefixes let the database skip ahead to the field it needs. It also supports types like dates, ObjectIds, and 64-bit integers that plain JSON can’t represent.
Is BSON the same as MessagePack or Protocol Buffers?
No. All three are binary formats, but they solve different problems. MessagePack optimizes for compact size. Protobuf requires a pre-defined schema. BSON prioritizes traversability — you can jump to any field without deserializing the whole thing. That trade-off is why BSON documents are often larger than their MessagePack equivalents.
Why is my BSON output bigger than the JSON input?
Totally normal for small documents. BSON adds a 4-byte document length, a 1-byte type marker per field, null terminators after every key name, and 4-byte string length prefixes. On a tiny object those overheads dominate. With larger documents — especially ones full of numbers — BSON starts to break even or win.
Can I convert this hex output back to JSON?
Not with this specific tool — it’s one-way, JSON to BSON. For the reverse direction you’d need a BSON-to-JSON decoder. The hex dump here is meant for inspection and debugging, not as an interchange format you’d feed back into another system.
Does this handle all BSON types like ObjectId and Date?
It handles the types that exist in standard JSON: strings, numbers (as doubles), booleans, null, objects, and arrays. Extended BSON types like ObjectId, Date, Binary, and Regex don’t have JSON equivalents, so they aren’t produced here. If you need those, you’d use MongoDB’s Extended JSON format as input with a different tool.