MediumπŸ‘€ 3-5 yearsπŸ‘€ 8-15 years 2 min read

JSON vs BSON β€” Interview Questions

Asked inAmazonMicrosoftDeloitteCognizant
#json#bson#mongodb#binary#serialization
Report issue

⚑ Short Answer

JSON is a text format; BSON (Binary JSON) is a binary encoding used by MongoDB. BSON adds types JSON lacks (ObjectId, native Date, binary data, Decimal128) and stores length prefixes so fields can be traversed/skipped fast. BSON is often larger than the equivalent JSON text but is quicker to parse and richer in types β€” you write JSON, MongoDB stores BSON.

β˜•Coffee Chat Question

Concept Made Simple

β€œWhat is the difference between JSON and BSON?”

🧠Mind Map Answer

Remember It Faster

JSON→text, human-readable, 6 types
BSON→binary, extra types, length-prefixed
Extra types→ObjectId, Date, binary, Decimal128
Trade-off→BSON: fast traverse, sometimes bigger

⌨️Hands-on Keyboard

Learn by Doing

javascript
// You write JSON-like documents...
db.users.insertOne({
  name: "Guru",
  createdAt: new Date(),          // stored as BSON Date
});
// ...MongoDB stores them as BSON: _id becomes an ObjectId,
// the date is a native BSON Date (not an ISO string).

πŸ”₯What If?

Think Beyond the Expected

If BSON can be larger than JSON, why does MongoDB use it?

Speed and richer types. BSON's length prefixes let the engine skip over fields without scanning byte-by-byte (fast indexing/traversal), and native types like Date, ObjectId, and Decimal128 avoid the lossy 'everything is a string/float' problem of JSON. The modest size overhead buys performance and type fidelity at the database layer.

πŸ˜‚Real World

MongoDB is the everyday example: the driver accepts JSON-like objects and stores BSON, which is why _id is an ObjectId and dates come back as real Date types rather than strings β€” a common surprise for developers new to Mongo.

🎯Interviewer's Expectation

Keywords they're listening for:

βœ“ JSON text vs BSON binaryβœ“ BSON extra types (ObjectId/Date/binary/Decimal128)βœ“ length-prefixed β†’ fast traverseβœ“ BSON can be largerβœ“ MongoDB storage format

⚠️Common Mistakes

  • βœ—Assuming BSON is always smaller than JSON
  • βœ—Thinking JSON has a native date/ObjectId type
  • βœ—Confusing the wire format with the storage format

βœ…Best Practices

  • βœ“Use JSON for interchange, let the DB use BSON
  • βœ“Rely on native BSON types instead of stringly-typed data
  • βœ“Consider protobuf/Avro for compact service-to-service traffic

πŸ”Follow-up Questions

  • 1Which types does BSON add over JSON?
  • 2Why can BSON be larger yet faster?
  • 3How does this compare to protobuf/Avro?

🧩Related Technologies

MongoDBObjectIdProtocol BuffersAvro

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly β€” AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: Advanced (JSON)
Interview question: "What is the difference between JSON and BSON?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.

Was this answer helpful?

Support our platform by exploring our recommended products.

As an Amazon affiliate, purchases through these links may earn us a small commission β€” at no extra cost to you. It helps keep Full Stack Interview Guru free.

Related Questions