【Transfer】The difference between BSON and JSON

Difference between BSON and JSON
BSON is a data format developed by 10gen. It is currently mainly used in MongoDB and is the data storage format of MongoDB. BSON is based on the JSON format. The reasons for choosing JSON for transformation are mainly the versatility of JSON and the schemaless characteristics of JSON.

BSON will mainly achieve the following three goals:

1. Faster traversal speed
For JSON format, too large JSON structure will cause data traversal to be very slow. In JSON, if you want to skip a document for data reading, you need to scan the document, and you need to perform troublesome data structure matching, such as matching brackets, and a big improvement of BSON over JSON is that it will convert JSON The length of each element exists in the head of the element, so that you only need to read the length of the element and you can directly seek to the specified point for reading.

2. Easier to operate
For JSON, the data storage is untyped. For example, if you want to modify a basic value, from 9 to 10, since it has changed from one character to two, it may be that all the content behind it needs to be shifted back one place. Can. With BSON, you can specify this column as a numeric column, then no matter the number grows from 9 to 10 or 100, we only modify the bit where the number is stored, which will not cause the total length of the data to become larger. Of course, in MongoDB, if the number increases from an integer to a long integer, it will still cause the total length of the data to become larger.

3. Added additional data types
JSON is a convenient data interchange format, but its types are limited. BSON adds the "byte array" data type to it. This makes binary storage no longer need to base64 conversion and then save to JSON. Significantly reduces computational overhead and data size.

Of course, sometimes, BSON has no space advantage over JSON. For example, for {"field":7}, only one byte is used in JSON storage, and if BSON is used, that is At least 4 bytes (32 bits)

At present, with the efforts of 10gen, BSON already has codec packages for multiple languages. And they are all open source under the Apache 2 license. And it's still evolving with MongoDB.

 Reprinted from http://www.cnblogs.com/jamesldj/p/3324564.html

 

Summarize:

1. bson can seek length

2. bson has a data type

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326487972&siteId=291194637