mongodb - What is BSON and exactly how is it different from JSON?

ID : 20303

viewed : 50

Tags : jsonmongodbbsonnosqljson

Top 5 Answer for mongodb - What is BSON and exactly how is it different from JSON?

vote vote

93

BSON is the binary encoding of JSON-like documents that MongoDB uses when storing documents in collections. It adds support for data types like Date and binary that aren't supported in JSON.

In practice, you don't have to know much about BSON when working with MongoDB, you just need to use the native types of your language and the supplied types (e.g. ObjectId) of its driver when constructing documents and they will be mapped into the appropriate BSON type by the driver.

vote vote

83

  • What's BSON?

    BSON [bee · sahn], short for Bin­ary JSON, is a bin­ary-en­coded seri­al­iz­a­tion of JSON-like doc­u­ments.

  • How is it different from JSON?

    BSON is designed to be efficient in space, but in some cases is not much more efficient than JSON. In some cases BSON uses even more space than JSON. The reason for this is another of the BSON design goals: traversability. BSON adds some "extra" information to documents, like length of strings and subobjects. This makes traversal faster.

    BSON is also designed to be fast to encode and decode. For example, integers are stored as 32 (or 64) bit integers, so they don't need to be parsed to and from text. This uses more space than JSON for small integers, but is much faster to parse.

    In addition to compactness, BSON adds additional data types unavailable in JSON, notably the BinData and Date data types.

Source: http://bsonspec.org/

vote vote

80

MongoDB represents JSON documents in binary-encoded format so we call it BSON behind the scenes.

BSON extends the JSON model to provide additional data types such  as Date and binary which are not supported in JSON also provide ordered fields in order for it to be efficient for encoding and decoding within different languages. 

In other word 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.

for more mongoDB Article : https://om9x.com/blog/bson-vs-json/

vote vote

65

MongoDB represents JSON documents in binary-encoded format called BSON behind the scenes. BSON extends the JSON model to provide additional data types and to be efficient for encoding and decoding within different languages.

vote vote

55

By using BSON encoding on top of JSON, MongoDB gets the capability of creating indexes on top of values that resides inside the JSON document in raw format. This helps in running efficient analytical queries as NoSQL system were known for having no support for Indexes.

Top 3 video Explaining mongodb - What is BSON and exactly how is it different from JSON?

Related QUESTION?