WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

MongoDB · Basic · question 3 of 100

What is BSON, and how is it related to JSON?

📕 Buy this interview preparation book: 100 MongoDB questions & answers — PDF + EPUB for $5

BSON is a binary representation of JSON data. It stands for Binary JSON. BSON was created to overcome some limitations of JSON, such as the lack of support for certain data types, like dates, and inefficient storage and parsing of JSON data. BSON is a binary-encoded serialization of JSON, which makes it more compact and efficient than JSON.

BSON and JSON are related in the sense that they share the same data model and syntax for representing data. BSON can be seen as an extension of JSON that adds additional data types and optimizations for binary storage and transmission.

BSON allows for more efficient and faster transmission of data between client and server, especially over a network, since it is more compact than JSON. BSON stores data in a binary format, which makes it more efficient to transmit and parse, as it can be read and written directly from memory.

Here is an example of how JSON data is represented in BSON:

JSON representation:

{
    "name": "John",
    "age": 30,
    "location": {
        "city": "New York",
        "state": "NY"
    }
}

BSON representation:

\\x32\\x00\\x00\\x00              // total document size
\\x02                           // element type 0x02 = String
name\\x00                       // field name
\\x04\\x00\\x00\\x00John\\x00      // field value
\\x10\\x00\\x00\\x00\\x0f          // element type 0x10 = Int32
age\\x00                        // field name
\\x1e\\x00\\x00\\x00              // field value
\\x03                           // element type 0x03 = Object
location\\x00                   // field name
\\x26\\x00\\x00\\x00              // total size of location object
\\x02                           // element type 0x02 = String
city\\x00                       // field name
\\x0b\\x00\\x00\\x00New York\\x00  // field value
\\x02                           // element type 0x02 = String
state\\x00                      // field name
\\x02\\x00\\x00\\x00NY\\x00         // field value
\\x00                           // end of document

As you can see, BSON has added additional information that is not present in the original JSON representation in order to make it more efficient when transmitting and storing data.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic MongoDB interview — then scores it.
📞 Practice MongoDB — free 15 min
📕 Buy this interview preparation book: 100 MongoDB questions & answers — PDF + EPUB for $5

All 100 MongoDB questions · All topics