Difference btw JSON and BSON ?
BSON vs JSON- What's the difference between them
BSON-
- BSON stands for Binary JSON. It is the data storage and network transfer format used internally by MongoDB.
- BSON is similar to JSON (JavaScript Object Notation), but it's in a binary format, meaning it stores data in 1s and 0s (machine-readable), not plain text.
- BSON (Binary JSON) is a binary-encoded serialization format used by MongoDB to store documents and make remote procedure calls. BSON extends the JSON model to provide additional data types, efficient encoding, and fast parsing.
Why BSON?
- MongoDB needed a format that:
- Could store rich data types (like Date, Binary, etc.)
- Is fast to parse
- Is compact in storage
- Supports traversing large data quickly
So, instead of using JSON (which is text-based and limited), MongoDB uses BSON under the hood.
Internal Use in MongoDB-
- Data Storage: All collections in MongoDB are stored as BSON documents.
- Data Transfer: BSON is also used to transfer data between the MongoDB server and clients.
- Indexing: BSON structure allows MongoDB to efficiently index and search documents.
ROLE OF BSON in MongoDB-
- Full Form - Binary JSON
- Used For - Document storage and transfer in MongoDB
- Advantages - Faster, supports more types, optimized for machine parsing
- Limitations - Slightly larger than JSON due to metadata overhead
- JSON stands for JavaScript Object Notation.
- Easy for humans to read and write.
- Easy for machines to parse and generate.
- Based on key-value pairs, similar to Python dictionaries or JavaScript objects.
- MongoDB is a NoSQL database that stores data in a flexible, JSON-like format called BSON (Binary JSON).
- But when you're interacting with MongoDB:
- You usually use JSON syntax to create, read, update, or delete data.
- MongoDB's query language is based on JSON-style documents.
- Storing documents (records)
- Structuring data
- Querying collections
- Performing updates and filters .
DIFFERENCE BETWEEN JSON and BSON-
Feature JSON (java script object notation) BSON (Binary JSON)
Format Text-based (UTF-8) Binary (Machine readable)
Human readable Yes No (not directly readable by users)
Used in mongodb Used for input/output Used for internal storage and data transformation
Speed Slower to parse and process Faster due to binary formatDatatypes limited(string,number,boolean) Extended(objectld,date,binaryint32,int64)
Used in APIs Frequently used in REST APIs Not used directly in APIsSupports Date? Only as string As actual date object
Size Smaller (No type metadata) Slightly larger
How They Work Together in MongoDB:
- You write: Queries and documents using JSON-like syntax.
- MongoDB converts it: Internally, MongoDB stores and transmits it as BSON.
- You receive: Responses in JSON-like format, even though internally it’s BSON.
- JSON: Easy for humans and used for communication (e.g., API calls, writing queries).
- BSON: Used by MongoDB to store and transmit data more efficiently and with more type support.
Name-Siddhi Bhosale
University: Sri Balaji University, Pune
School: School of Computer Studies
Course: BCA (Bachelor of Computer Applications)
Interests: NoSQL, MongoDB, and related technologies
Very Useful π
ReplyDeleteGoodππ
ReplyDeleteExcellent work π
ReplyDeleteGoodππ»
ReplyDeleteNice blog.... Very informative π
ReplyDeleteVery insightful
ReplyDeletegreat work...really impressive
ReplyDeleteExceptional Workπ....Keep It Upπ€
ReplyDeleteGreat job too informative ππ»
ReplyDeleteNicely explain
ReplyDeleteInformative blog
ReplyDeleteExcellent ππ»
ReplyDeleteVery helpful π
ReplyDeleteGreat job π
ReplyDeleteImpressive π
ReplyDeleteVery helpfulπ
ReplyDelete