Comparing JSON and BSON in MongoDB

Comparing JSON and BSON in MongoDB

In this article, I am going to discuss what is the difference between JSON and BSON File Formats in MongoDB. Please read our previous article where we discussed How to Create MongoDB Documents with Examples.

Comparing JSON and BSON in MongoDB

JSON: JSON is known as JavaScript Object Notation. It is a human-readable data interchange format. It is a language-independent file format and is lightweight. It is the commonly used data format for asynchronous browser-server communication. Using JSON, we can also send information very easily. It is a combination of key/value pairs and an array. We can also allow to embedded one JSON document into another up to a maximum of 100 documents. String, numbers, array true, false, null, object, etc. are some data types that are supported by JSON.

BSON: BSON is known as Binary-JSON. It is a binary format so it is not in a human-readable format. BSON is used to encrypt JSON data. It can be easily parsed and provide additional datatypes over the JSON. It is a language-independent file format and is lightweight. It can traverse easily across the network. Or we can say that it is a binary structure that encodes type and length information and can be traversed must more quickly as compared to JSON.

Comparing JSON and BSON in MongoDB
JSON BSON
It stands for JavaScript Object Notation It stands for Binary JavaScript Object Notation
It is a standard file format type. It is a binary file format type.
Some basic data types supported by JSON: string number, Boolean, null, etc. Some basic data types supported by BSON: date, timestamp, etc.
It is slower than JSON It is faster than JSON
It consumes more space as compared to BSON It consumes less space as compare to JSON
JSON used for the transmission of data BSON is used for storing data
It does not have encoding and decoding techniques It has faster encoded and decoding techniques.
Databases like AnyDB, redid, etc use JSON format to store data. MongoDB uses BSON format to store data
It does not require to be parsed because it is already in a human-readable format. It does require to be parsed and it can be parsed easily by the machines.
In a JSON file, if you want to read any specific information then you must go through the whole content. In a BSON file, you can use indexes to read a piece of specific information. With the help of indexes, you need not go through all the content, it will return only the specified information.

In the next article, I am going to discuss How MongoDB Works. Here, in this article, I try to explain what is the difference between JSON and BSON File Formats in MongoDB. I hope you enjoy the JSON and BSON file formats in the MongoDB article.

Leave a Reply

Your email address will not be published. Required fields are marked *