Let us discuss in this blog,
What is JSON (JavaScript Object Notation)?
What is BSON? (Binary JSON)

Before understanding BSON, let's try to understand what is JSON (JavaScript Object Notation)?

What is JSON (JavaScript Object Notation)?

  • JSON are key-value pairs.
  • The value can be a number, string, function, or even another object.
    Example:
{
"_id": 1,
"name" : { "first" : "John", "last" : "Backus" },
"contribs" : [ "Fortran", "ALGOL", "Backus-Naur Form", "FP" ],
"awards" : [
{
"award" : "W.W. McDowell Award",
"year" : 1967,
"by" : "IEEE Computer Society"
}, {
"award" : "Draper Prize",
"year" : 1993,
"by" : "National Academy of Engineering"
}
]
}
  • JSON became very popular and it has been used in many different cases, like APIs, Configuration files, Log messages, etc...
  • However, there are several issues if you use JSON inside of a database:
    1) JSON is a text-based format, and text parsing is very slow
    2) JSON only supports a limited number of basic data types.
    3) Traversing through JSON is slow.
  • In order to overcome this issue, BSON was invented. Let us see what is BSON below.

What is BSON?

  • BSON simply stands for “Binary JSON”. It stores the JSON in binary format.
  • BSON’s binary structure adds some extra information to documents, like the length of strings and sub-objects.
  • MongoDB stores the data on the disk as BSON in your db-data path directory, which is usually /data/db.

Advantages:

  • Since BSON has extra information about the documents, like the length of strings and sub-objects, it can be parsed much more quickly than JSON.
  • BSON has more data types, like dates, binary data, integer, float, long, decimal128..etc...

Disadvantages:

  • Since BSON has extra information about the documents, it takes more space compared to JSON.

Thank You…

MERN stack developer