Convert JSON to BSON
Convert JSON data structure to BSON (Binary JSON) format.
Input (JSON)
Options
Output (BSON)
What It Does
Convert JSON data to BSON (Binary JSON) format and explore exactly how MongoDB stores your documents under the hood. BSON is the binary-encoded serialization format that MongoDB uses internally to store and transfer data — and while it shares structural similarities with JSON, the two formats have meaningful differences in type richness, storage size, and traversal performance that every database developer should understand. This tool takes any valid JSON input and produces a detailed BSON representation, annotating each value with its corresponding BSON type code. You can immediately see how a JavaScript number becomes a BSON Double or Int32, how a date string maps to a BSON Date object, and how nested documents and arrays are encoded. Side-by-side size comparisons let you gauge whether your documents will be larger or smaller after BSON serialization — a practical consideration when designing schemas for high-volume MongoDB collections. Whether you're a backend developer integrating a Node.js application with MongoDB, a data engineer migrating relational data into a document store, or a student learning NoSQL concepts, this tool gives you a transparent view into BSON encoding without needing a running MongoDB instance. Use it to validate type mappings, anticipate storage overhead, and catch data type mismatches before they become runtime bugs in production.
How It Works
The Convert JSON to BSON applies its selected transformation logic to your input and produces output based on the options you choose.
It applies a fixed set of transformation rules to your input, so the output is stable and easy to verify.
All processing happens in your browser, so your input stays on your device during the transformation.
Common Use Cases
- Previewing exactly how a JSON document will be stored in a MongoDB collection before writing application code.
- Verifying BSON type mappings when migrating data from a relational database to MongoDB to ensure numeric and date fields are encoded correctly.
- Estimating document storage size in MongoDB during schema design to avoid hitting the 16 MB BSON document size limit.
- Debugging unexpected data type behavior in MongoDB queries, such as a field being stored as Double instead of Int32.
- Learning BSON encoding as part of a MongoDB certification or database development course.
- Auditing third-party JSON payloads to understand how they will be deserialized by a MongoDB driver.
- Comparing the storage efficiency of different JSON structures to choose the most compact schema for a high-throughput collection.
How to Use
- Paste or type your valid JSON object or array into the input panel on the left side of the tool.
- The tool will instantly parse your JSON and display the BSON representation with each field annotated by its BSON type code (e.g., Double, String, ObjectId, Date, Boolean, Array, Document).
- Review the type annotations carefully — pay close attention to numeric fields, which may be mapped to Double, Int32, or Int64 depending on their value range.
- Check the size comparison panel to see the byte size of your original JSON versus the encoded BSON output, helping you understand the storage overhead implications.
- If any field is not mapping to the BSON type you expect, adjust your JSON — for example, use an ISO 8601 date string to ensure proper Date type detection.
- Copy the annotated BSON structure or export the results to use as reference documentation for your MongoDB schema design.
Features
- Automatic BSON type annotation for every field, including nested documents and array elements, so you know exactly how MongoDB will interpret your data.
- Side-by-side byte size comparison between the raw JSON input and the BSON-encoded output to help you plan storage budgets.
- Support for the full range of BSON data types including Double, String, Document, Array, Binary, ObjectId, Boolean, Date, Null, Int32, Int64, and Decimal128.
- Real-time conversion with instant feedback as you type or paste JSON, eliminating the need to manually install BSON libraries to inspect encodings.
- Clear visual differentiation between BSON type codes and values, making it easy to scan complex, deeply nested documents at a glance.
- Handles edge cases such as JavaScript's maximum safe integer boundaries, correctly distinguishing between Int32 and Int64 representations.
- No server-side processing — your data is converted entirely in the browser, keeping sensitive document contents private.
Examples
Below is a representative input and output so you can see the transformation clearly.
{"name":"Ada","score":9}BSON (hex): 16000000026e616d650004000000416461000973636f72650009000000
Edge Cases
- Very large inputs may take a few seconds to process in the browser. If performance slows, split the input into smaller batches.
- Mixed formatting (tabs, line breaks, or inconsistent delimiters) can affect output. Normalize spacing first if needed.
- Convert JSON to BSON follows the selected options strictly. If the output looks unexpected, re-check option settings and input format.
Troubleshooting
- Output looks unchanged: confirm the input contains the pattern this tool modifies and that the correct options are selected.
- Output differs from a previous run: confirm that the input and every option match, because deterministic tools should repeat when the settings are identical.
- Unexpected characters: check for hidden whitespace or encoding issues in the input and try normalizing first.
- Slow processing: reduce input size or try a modern browser with more available memory.
Tips
When designing MongoDB schemas, prefer Int32 over Double for integer counters and IDs where possible — BSON Doubles use 8 bytes while Int32 uses only 4, which adds up significantly across millions of documents. If you're working with timestamps, always use a proper ISO 8601 date string (e.g., "2024-01-15T10:30:00Z") so the tool and MongoDB drivers map your value to the efficient BSON Date type rather than a plain String. Keep an eye on the total document size shown in the comparison panel — MongoDB enforces a hard 16 MB limit per document, and deeply nested structures with large arrays can approach that ceiling faster than you might expect.
Frequently Asked Questions
What is BSON and how is it different from JSON?
BSON stands for Binary JSON and is the binary-encoded serialization format used by MongoDB to store and transfer documents. While JSON is a text-based, human-readable format with a limited set of data types (string, number, boolean, array, object, null), BSON extends this with additional types such as Int32, Int64, Double, Decimal128, Date, ObjectId, Binary, and Regular Expression. BSON documents also include explicit length prefixes that allow the database engine to skip fields without parsing the entire document, resulting in faster read operations. The trade-off is that BSON is not human-readable without a decoder.
Why does MongoDB use BSON instead of plain JSON?
MongoDB uses BSON for three primary reasons: richer data types, faster traversal, and native binary support. Plain JSON represents all numbers as a single "number" type, which means a database cannot distinguish between an integer and a floating-point value without application-level logic. BSON provides explicit numeric types, preserving precision for financial and scientific data. Its length-prefixed structure also allows MongoDB to navigate to specific fields in a document without reading the entire byte sequence, significantly improving query performance on large documents.
What is the maximum size of a BSON document in MongoDB?
MongoDB enforces a maximum BSON document size of 16 megabytes. This limit exists to prevent any single document from consuming excessive memory during query execution and to encourage proper data modeling — very large documents are typically a sign that data should be split across multiple documents or a separate collection. If you need to store files larger than 16 MB, MongoDB recommends using GridFS, which splits large files into chunks and stores them as a sequence of BSON documents.
How does this tool convert JSON to BSON?
This tool parses your JSON input in the browser and maps each value to its most appropriate BSON type using the same rules MongoDB drivers follow. For example, integer values within the 32-bit signed range are mapped to Int32, larger integers to Int64, decimal numbers to Double, and ISO 8601 date strings to BSON Date objects. The tool then displays the annotated structure alongside a byte-size comparison between the raw JSON and the BSON-encoded output. No data is sent to a server — all processing happens client-side.
Will a JSON number always become a BSON Double?
Not necessarily — it depends on the MongoDB driver and the value itself. The official BSON specification defines multiple numeric types: Double (64-bit IEEE 754 floating point), Int32 (32-bit signed integer), Int64 (64-bit signed integer), and Decimal128 (128-bit decimal floating point for high-precision arithmetic). Many drivers, including the official Node.js driver, default to Double for JSON numbers unless you explicitly use typed constructors like `new Int32(42)`. This tool mirrors that behavior and shows you the default type mapping so you can make an informed decision about whether to enforce stricter types in your application code.
Is BSON always smaller than JSON in terms of storage size?
No — for small, text-heavy documents, BSON is often slightly larger than the equivalent JSON because each BSON element includes a one-byte type code and a null-terminated key string in addition to the value. A simple document like `{"name": "Alice"}` takes fewer bytes as JSON text than as a BSON-encoded document. However, for documents containing binary data, dates, or large integers, BSON's native type encoding eliminates the overhead of JSON workarounds like Base64, and the overall payload can be more compact. The size comparison panel in this tool shows you the exact difference for your specific document.