Home » JSON vs BSON

JSON vs BSON

Before knowing the differences between the JSON and BSON, we should know about JSON and BSON separately.

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.

JSON Example:

In the above JSON example, “id” is defined. The name of the id starts with a ‘_’ underscore character. It is mandatory to provide the ‘id’ to the json document. If we do not provide the ‘id‘ to the json document, the system id is created. In the above, subject is an array that contains the values Maths, English, and Hindi. An address is a object as address contains the çurly bracket.

The ‘_id’ is a 12 bytes hexadecimal number that provides the uniqueness of every document. We can add the ‘_id’ field in a json document. If we do not provide the ‘_id’ field in a json document, then the system itself generates the ‘_id’.

These 12 bytes are divided into four sections:

  • First 4 bytes is the current timestamp.
  • The next 3 bytes is the machine id.
  • The next 2 bytes is the process id.
  • The last 3 bytes is an incremental value.

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.

Differences between JSON and BSON.

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.

Next TopicJSON Placeholder

You may also like