Sunday, March 24, 2019

What is difference between JSON and BSON

difference between JSON and BSON

MongoDB represents JSON documents in a binary-encoded format so-called BSON behind the scenes.

BSON is a format specializing in efficient storing of JSON-like documents, which besides supporting the traditional JSON data types it also supports dates and binary data natively.

BSON extends the JSON model to provide additional data types such as Date and binary which was are not supported in JSON also provide ordered fields,.

In other words, we can say  BSON is just binary JSON ( a superset of JSON with some more data types, most importantly binary byte array ).

MongoDB using as a serialization format of JSON include with encoding format for storing and accessing documents. simply we can say BSON is a binary encoded format for JSON data.

Difference Between JSON and BSON

JavaScript Object Notation (JSON) is a standard file format which uses human type readable text to transmit data with attribute value pairs and array data types. This is one of the most common data formats which are mainly used for asynchronous browser-server communication.
JSON is a language independent format. The fundamental of it includes JavaScript and there are many programming languages today which makes use of the code to generate and parse the JSON format related data.
JSON Data Format:
{"widget": {
    "debug": "on",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    "image": { 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    "text": {
        "data": "Click Here",
        "size": 36,
        "style": "bold",
        "name": "text1",
        "hOffset": 250,
        "vOffset": 100,
        "alignment": "center",
        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"

BSON, on the other hand, is a computer interchange format which is mainly used for data storage and as a network transfer format in the MongoDB database. It is a simple binary form which is used to represent data structures and associative arrays (often called documents or objects in MongoDB). BSON stands for binary JSON which consist of a list of ordered elements containing a field name, type, and a value. Field name types are typically a string.

The BSON type supports the dates and binary data and because of its nature, this is not in a readable form whereas normal JSON files consist of a key-value pair. It is not a mandate that the BSON files are always smaller than JSON files but it surely skips the records which are irrelevant while in case of JSON you need to parse each byte. This is the main reason for using it inside MongoDB.

The BSON type format is lightweight, highly traversable and fast in nature. BSON implementation is used for supporting embedding objects and arrays within other objects. Inside BSON objects indexes can be built and the objects are matched against query expressions on the top level and BSON keys. BSON is that binary encoding JSON document which is used to store documents in collections. Support for data types like binary and date which aren’t supported in JSON are added into BSON.

In practicality, much information about BSON is not needed. Using only the native types of the language and the supplied types such as the ObjectID of the driver is needed and the mapping will be done on its own to the BSON type.
How BSON Data Formatted:

No comments:

Post a Comment

Post Top Ad

Your Ad Spot