JSON vs BSON
What is JSON?
JSON is Javascript Object Notation. It is a standard format used for storing and interchanging the data. JSON is a user readable and it is a completely language format. It is light weight. When we read the JSON data of any application so that is language independent. We can send information through JSON very easily. JSON is basically a combination of key/value pair and arrays. In JSON, we can embed more than one json documents in a single json file. The maximum 100 documents can be embedded in a single json document.
The data types supported by JSON are string, number, object, array, true, false, and null.
What is BSON?
BSON is a Binary Javascript Object notation. It is not in the human-readable format as it is in the binary format. In MongoDB, BSON is used to encrypt the JSON data. It provides additional data types over the JSON data. It is also a language independent, and can be easily parsed.
It supports the adding of documents and arrays within other documents and arrays.
BSON has following three characteristics:
- Lightweight: When used over the network, the JSON keeps the overhead involved in processing extra header data to a minimum.
- Traversable: It is designed to traverse easily across the network. This helps in its role as the primary data representation for MongoDB.
- Efficient: It allows C data types that allow easy and quick encoding and decoding of data.
JSON vs BSON
The following are the differences between JSON and BSON:
JSON | BSON |
---|---|
JSON is javascript object notation. | BSON is Binary Javascript Object notation. |
It is a standard file format type. | It is a binary file format type. |
JSON contains some basic data types like string, numbers, Boolean, null. | BSON contains some additional data types like date, timestamp, etc. |
Databases like AnyDB, redis, etc. stores the data into the JSON format. | The data in MongoDB is stored in a BSON format. |
JSON requires less space as compared to BSON. | BSON requires more space as compared to JSON. |
It is comparatively less faster than BSON. | It is faster as compared to BSON. |
It is used for the transmission of data. | It is used for the storage of data. |
It does not have encoding and decoding technique. | It has faster encoding and decoding technique. |
If we want to read any particular information from the JSON file then it needs to go through whole content. | In BSON, indexes concept is used that skips all the content which are not in use. |
JSON format does not require to be parsed as it is already human readable. | It requires to be parsed as it can be easily parsed by the machines. |
JSON is a combination of objects and arrays where an object is a collection of key-value pairs while array is an ordered list of elements. | The binary encoding technique provides some additional information such as length of the string and object subtypes. BinData and Date are the additional data types supported by BSON over the JSON. |