Tools

Home
JSON FormatterSQL FormatterJS ValidatorMinify CSS
Merge PDFCompress PDFImage to PDF
JPG to PNGPNG to WebPCrop Image

JSON to BSON Converter

Paste JSON to view its BSON binary representation as a hex dump with size calculations

Your files never leave your browser
JSON Input0 chars, 0 lines
BSON Hex Output0 bytes
Ready·

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

Paste JSON
→
Encode to BSON
→
View Hex Dump

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.

INPUT
{"name":"Alice","age":29,"active":true}
OUTPUT
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 bytes

Nested Object with Array

Testing how BSON handles embedded documents and arrays — useful when you’re verifying subdocument encoding in a custom driver.

INPUT
{"order":{"id":5012,"items":["pen","notebook"],"shipped":false}}
OUTPUT
Hex dump showing nested doc with type 0x03 (embedded doc), type 0x04 (array), and type 0x08 (boolean) markers. BSON Size: ~95 bytes

Empty 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.

INPUT
{}
OUTPUT
00000000: 05 00 00 00 00 BSON Size: 5 bytes

Who Uses This

🛠️ Backend Developers

Debug MongoDB wire protocol messages and verify BSON encoding in custom drivers or ORMs.

🗄️ Database Engineers

Compare document sizes before and after schema changes to estimate storage impact.

🎓 CS Students

Study binary encoding formats and see how text-based JSON translates to typed binary bytes.

🔍 QA Engineers

Validate that API payloads serialize correctly by checking the raw BSON output against expected byte patterns.

Common Mistakes

Passing a bare string or number as input

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}.

Expecting BSON to always be smaller than JSON

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.

Trailing commas or single quotes in JSON

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

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.

Share: