{# canonical_base is the OWNING tenant's origin: all 16 Peasy domains serve the same catalogue, so a page rendered by a non-owner points its canonical at the owner instead of competing with it. Falls back to this site for static/self-owned pages. #}
🍋
Menu

JSON vs BSON

JSON is a text format defined by RFC 8259 and ECMA-404; BSON is the binary document format specified at bsonspec.org and used as MongoDB's storage and wire representation. BSON is not simply JSON compressed. It adds a type system JSON lacks — 32-bit and 64-bit integers, doubles, Decimal128, dates, binary data, ObjectId — and it prefixes every document and string with its length so a reader can skip a field without parsing it. Those additions cost bytes: for small documents of short strings, BSON is frequently larger than the equivalent JSON.

At a glance

  JSON BSON
Specification RFC 8259, ECMA-404 bsonspec.org
Representation UTF-8 text Binary
Human readable Yes No, without a decoder
Number types One (an unqualified number) int32, int64, double, Decimal128
Dates None; conventionally an ISO 8601 string Native UTC datetime (int64 milliseconds)
Binary data Base64 string, about 33% overhead Native binary subtype, no expansion
Traversal Sequential parse Length-prefixed; fields can be skipped
Size limit None in the specification 16 MB per document in MongoDB
Primary use Web APIs, configuration, interchange MongoDB storage and wire protocol

Key differences

  • JSON has a single number type, so a consumer cannot tell an integer from a float without inspecting the text. BSON records the type explicitly, which is what makes round-tripping a 64-bit identifier safe.
  • Binary payloads must be base64-encoded to travel in JSON, adding roughly a third to their size. BSON stores the bytes directly.
  • BSON's length prefixes let a driver jump over fields it does not need. JSON must be scanned from the start.
  • Those prefixes and type bytes are why BSON is often the larger of the two for small records: a short string carries its length and a type marker that JSON spends only quotes on.
  • Neither format compresses. Size comparisons between them are usually settled by the compressor applied afterwards rather than by the encoding itself.

When to choose which

JSON

  • Public APIs and any payload a person may need to read in a log or a browser.
  • Configuration files kept under version control, where a text diff matters.
  • Interchange between systems that do not share a MongoDB driver.

BSON

  • Documents stored in or transmitted to MongoDB.
  • Records that must preserve integer width, decimal precision or a native date.
  • Payloads dominated by binary blobs that would otherwise be base64-encoded.

Frequently asked questions

Is BSON smaller than JSON?

Not reliably. BSON adds a length prefix and a type byte to each element, so small documents of short strings are often larger in BSON. Documents dominated by numbers or binary data are usually smaller.

What types does BSON add over JSON?

Among others: 32-bit and 64-bit integers, double, Decimal128, UTC datetime, binary data with subtypes, ObjectId, regular expression and timestamp.

Why is there a 16 MB limit?

The 16 MB ceiling is a MongoDB constraint on a single document rather than a property of the BSON format itself. Larger payloads are split, or stored with GridFS.

Can BSON be converted to JSON without loss?

Not directly, because JSON has no way to express the distinction between an int64, a double and a Decimal128. Extended JSON preserves the type information by wrapping values in annotating objects.

Is BSON a standard?

It is an open specification published at bsonspec.org with independent implementations, but it is not an IETF or ECMA standard as JSON is.

Related reference