MongoDB, JSON, and BSON: What Actually Gets Stored
Understand how MongoDB uses JSON and BSON: the binary format behind documents, extra data types like ObjectId and Date, Extended JSON modes, and why your stored data differs from the JSON you see.
MongoDB is famous for storing JSON documents, but that is a useful simplification — under the hood it stores BSON, a binary superset of JSON. The distinction matters the moment you hit dates, ObjectIds, or large numbers. This guide explains the relationship between JSON and BSON, the extra types BSON adds, and how Extended JSON lets you move data in and out without losing information.
MongoDB stores BSON, not JSON
When you write a document to MongoDB, the driver serializes your JSON-like object into BSON — Binary JSON — for storage and transport. BSON is a binary-encoded representation of JSON data with extensions. The shell and drivers show you JSON-looking output, so it feels like JSON, but the on-disk and on-the-wire format is BSON. Understanding this explains several behaviors that otherwise look surprising.
Why BSON instead of plain JSON?
BSON is built for databases. It prefixes documents and fields with type and length information, so a query engine can skip and traverse fields without parsing the whole document — much faster than scanning text JSON. It also encodes binary data efficiently. The trade-off is human readability: BSON is not meant to be read directly, which is why tools translate it back to JSON for display.
Types BSON adds over JSON
- ObjectId — the 12-byte identifier MongoDB assigns to the _id of every document.
- Date — a real 64-bit datetime type, which JSON lacks entirely.
- Distinct number types — 32-bit int, 64-bit long, double, and high-precision Decimal128, where JSON has only a single number type.
- Binary data (BinData) — for storing images, files, and UUIDs efficiently.
- Other types like Timestamp and Regular Expression that have no JSON equivalent.
The integer-versus-float problem
JSON does not distinguish integers from floating-point numbers — it has one number type. BSON does, which is why a value can round-trip incorrectly if you treat MongoDB data as plain JSON: a 64-bit integer ID might be coerced to a double and lose precision. When exact numeric types matter, rely on BSON's distinct types (and Decimal128 for money) rather than generic JSON numbers.
Extended JSON for import and export
Because JSON cannot represent ObjectId, Date, or Decimal128, MongoDB defines Extended JSON (EJSON): a JSON-compatible way to encode BSON types using special wrapper keys. It comes in two modes — canonical, which is precise and preserves exact types for round-tripping, and relaxed, which is more human-readable but lossy for some types. mongoexport and drivers use Extended JSON so you can move data through plain JSON tooling without losing type information.
{
"_id": { "$oid": "65f0c3a1b2c3d4e5f6a7b8c9" },
"createdAt": { "$date": "2026-05-08T14:30:00Z" },
"amount": { "$numberDecimal": "19.99" }
}Working with MongoDB JSON
When you export documents or paste them from the shell, you get JSON (often Extended JSON) that you can inspect with normal tools. A formatter makes a dense export readable, a validator confirms it is well-formed, and a tree viewer helps you navigate large nested documents. Just remember that the ObjectId and Date wrappers you see are Extended JSON encodings of BSON types, not plain JSON values.
Frequently asked questions
Does MongoDB use JSON or BSON?
Both, at different layers. You work with JSON-like documents, but MongoDB stores and transmits them as BSON — a binary superset of JSON. The shell and drivers display BSON as JSON, which is why it feels like you are using JSON directly.
What is the difference between BSON and JSON?
JSON is a human-readable text format; BSON is a binary encoding of JSON-like data with length and type prefixes for fast traversal. BSON also adds types JSON lacks, such as Date, ObjectId, Decimal128, and binary data.
Why does MongoDB use BSON?
Because BSON is optimized for databases: its length and type prefixes let the engine traverse and skip fields without parsing the whole document, it stores binary data efficiently, and it supports rich types. The cost is that it is not human-readable.
What is Extended JSON in MongoDB?
Extended JSON (EJSON) is a JSON-compatible way to represent BSON types that plain JSON cannot, like ObjectId and Date, using special wrapper keys. It has a precise canonical mode and a more readable relaxed mode, and tools like mongoexport use it.
Why do MongoDB numbers lose precision in JSON?
Because JSON has a single number type and cannot distinguish a 64-bit integer from a double. Treating BSON data as plain JSON can coerce a large integer to a float and lose precision; use BSON's distinct types or Extended JSON to preserve them.
Related tools
Try these tools
JSON Formatter & Beautifier
Format, prettify, and beautify messy JSON with configurable indentation and key sorting.
JSON Validator
Validate JSON instantly with precise, human-readable error messages and line numbers.
JSON Viewer & Tree Explorer
Explore JSON with an interactive collapsible tree view.
JSON Repair & Fix
Fix invalid JSON: trailing commas, quotes, unquoted keys, and LLM markdown fences.