MongoDB โ JSON vs BSON Deep Dive
Compare human-readable JSON against binary BSON. Learn about Extended JSON (EJSON) formats and how MongoDB driver serialization works.
1Side-by-Side Comparison: JSON vs BSON
| Feature | JSON (JavaScript Object Notation) | BSON (Binary JSON) |
|---|---|---|
| Format | Text-based string format | Binary encoded bytes |
| Readability | Human-readable | Machine-readable (requires parser) |
| Data Types | String, Number, Boolean, Array, Object, Null | 20+ Data types (Date, ObjectId, Decimal128, BinData) |
| Traversal Speed | Slow (must parse entire text string) | Fast (contains length prefixes & index offsets) |
| Storage Efficiency | Space inefficient for large numbers/dates | Highly optimized for disk and memory RAM |
2MongoDB Extended JSON (EJSON)
When converting BSON data to standard JSON for REST APIs, special BSON types are serialized using MongoDB Extended JSON (EJSON) specification:
Canonical EJSON Example
{
"_id": { "$oid": "65d8f1e2a9b3c4d5e6f7a8b9" },
"createdAt": { "$date": "2026-08-26T12:00:00Z" },
"price": { "$numberDecimal": "99.95" }
}