Compare
BSON vs JSON
BSON is a length-prefixed binary document format with JSON-like structures and additional types such as dates, binary values, and ObjectId. JSON is a text format defined by RFC 8259, valued for readability and broad tooling.
Which format should you choose?
Consider BSON for MongoDB-compatible documents and explicit date, binary, or identifier types. JSON is often easier for human inspection, web APIs, and text-based configuration.
Good fit for BSON
Serializing MongoDB documents · Exchanging documents between BSON-aware tools
- Preserving types such as dates and binary values
- Working with drivers and tools that read and write BSON
Good fit for JSON
Web APIs, configuration files, and data exchange
- Transferring structured data
Basic information
| Field | BSON | JSON |
|---|---|---|
| Extension | .bson | .json |
| MIME type | application/bson | application/json |
| Common uses | Serializing MongoDB documents · Exchanging documents between BSON-aware tools | Web APIs, configuration files, and data exchange |
| How to open | Read it with mongorestore or a BSON-aware tool or library. To inspect its contents, convert BSON to Extended JSON or another readable representation. Do not edit the binary file in a text editor. | Open it in a text editor, IDE, or JSON-aware viewer. |
| Export or convert | When converting to JSON, dates, ObjectId, and binary values may need Extended JSON notation or application-specific representations because standard JSON has no matching types. If you need a round trip, choose a method that preserves type information and test it with real data. | Applications or conversion tools can convert it to formats such as CSV. |
Choose by use case
Preserving types such as dates and binary values
Serializing MongoDB documents · Exchanging documents between BSON-aware tools
BSONWorking with drivers and tools that read and write BSON
Serializing MongoDB documents · Exchanging documents between BSON-aware tools
BSONTransferring structured data
Web APIs, configuration files, and data exchange
JSONKey point 1
BSON stores document lengths and element types in binary and includes types such as date, binary, and ObjectId. JSON is textual and has no dedicated core date or byte-string type.
More on the differencesKey point 2
BSON distinguishes int32, int64, and double. JSON numbers do not carry those distinct type labels, so converters and runtimes may handle range or precision differently.
More on the differencesMore on the differences
Use BSON where the database or protocol expects BSON types and document framing. Use JSON where text interoperability and inspection matter. Specify how special values map, and test the exact drivers and consumers.
- BSON is not simply JSON serialized as binary. Its specification defines a typed document representation with explicit lengths and BSON-specific values.
- Converting BSON to JSON may lose ObjectId identity, date precision or timezone assumptions, binary subtype, Decimal128 behavior, integer precision, or duplicate-key semantics.
- Check numeric ranges, array order, embedded documents, null and missing-field behavior, binary data encoding, and the conventions used by any JSON extended representation.
Frequently asked questions
Can standard JSON represent every BSON value directly?
No. JSON has no native ObjectId, date, or arbitrary byte-string type. Applications use conventions or extended JSON, which must be agreed on by both sides.