Skip to content

MongoDB Fundamentals

JSON vs BSON

Why MongoDB stores BSON, which types JSON cannot represent, and why that matters.

BeginnerAbout 5 minutes

You write documents that look like JSON. MongoDB stores them as BSON — Binary JSON. Same shape, extra types, a binary layout the server can walk quickly.

{
  "name": "Rahul",
  "age": 28,
  "createdAt": "2026-08-20T00:00:00.000Z"
}
JSON: dates are strings, numbers are just numbers, no ObjectId
{
  _id: ObjectId("64a1b2c3d4e5f6a7b8c90001"),
  name: "Rahul",
  age: 28,
  createdAt: ISODate("2026-08-20T00:00:00.000Z")
}
BSON: typed values the server understands natively

Why BSON exists

JSON cannot represent an ObjectId, a real Date, or a decimal that does not round like a float. Everything would become a string or a Double, and you would parse it back in application code. BSON keeps those types. It is also length-prefixed, so the server can skip a field without parsing the rest of the document.

You almost never look at the bytes. Drivers and the shell show you JSON-like objects. The important part is the types: Date stays a Date, ObjectId stays an ObjectId, Decimal128 stays exact.

  • DateISODate(...), not a string you have to parse on every query.
  • ObjectId — the default _id. Next lesson.
  • Decimal128 — exact decimals for money. Covered with the other types.
  • Int32 / Int64 / Double — JSON has one number type; BSON does not.
  • Binary — raw bytes when you actually need them. Rare in API code.

Interview question

Why does MongoDB use BSON instead of JSON?

Think about it first.