BSON Hex Viewer
Paste a one-field JSON object to see its BSON bytes in hex.
Result
How it is calculated
The document is laid out as int32 total length | type byte | key as C-string | value | 0x00. The total length is little-endian and counts itself, the element and the final terminator byte. A text value gets type 0x02 and is stored as an int32 length (text bytes plus one) followed by the UTF-8 bytes and a 00 terminator. A whole-number value gets type 0x10 and is stored as four little-endian bytes. Only a JSON object with exactly one field is accepted, and its value must be a string or an integer from -2147483648 to 2147483647. Anything else returns no result. Bytes are shown in uppercase hex separated by spaces, with no per-field annotation.
Worked example
For {"hello":"world"}: the key hello takes 5 bytes plus a 00 terminator (6). The value world is 5 bytes plus a terminator, so its length prefix is 06 00 00 00 and the value part takes 4 + 6 = 10 bytes. Add the type byte 02 (1 byte) and the 4-byte total length and the final 00 (1 byte): 4 + 1 + 6 + 10 + 1 = 22. The first four bytes are therefore 16 00 00 00 (hex 16 = 22), and the tool reports a total length of 22 bytes, field type string (0x02).
Common mistakes
- Pasting a document with two or more fields, a nested object or an array. The viewer encodes exactly one field, so these give no result.
- Using booleans, decimals such as 1.5, null or integers above 2147483647. Only strings and 32-bit integers are supported, and a large number would need int64 (0x12), which is not offered here.
- Counting characters instead of bytes. A non-ASCII character like é takes two UTF-8 bytes, so the length prefix and total length grow by more than the visible text suggests.
- Reading the length bytes as big-endian. BSON stores integers little-endian, so 22 appears as 16 00 00 00, not 00 00 00 16.
- Forgetting that the string length prefix includes the terminating zero byte, so it is one larger than the text length.
About this calculator
BSON (Binary JSON) is the binary-encoded serialization format MongoDB uses to store documents and exchange them over its wire protocol — it extends JSON with extra types like dates and binary data, and every element in the byte stream follows the same layout: a one-byte type code, a null-terminated field-name string, and then the value encoded according to its type (e.g., a 32-bit little-endian integer, or a 4-byte length prefix followed by UTF-8 bytes for a string).
This viewer takes a small JSON object with a single field (a string or a 32-bit integer value) and encodes it exactly as MongoDB's driver would, then displays the resulting bytes as hexadecimal together with the total document length and the field's type — the hex itself is not labeled, but you can read the length prefix, type byte, field name and value bytes off the layout above — so you can see how JSON's text representation maps onto BSON's compact binary layout without needing to run a database driver.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
This viewer encodes a one-field object only, so use it to learn the byte layout rather than to inspect real database documents. The input {"n":5} gives 0C 00 00 00 10 6E 00 05 00 00 00 00, 12 bytes, with 10 marking a 32-bit integer and 6E being the letter n. Two fields return nothing. Which other BSON types would you want to see supported next?