Bson is a data format developed by 10gen, which is currently used primarily in MongoDB and is a data storage format for MongoDB. Bson based on JSON format, the main reason to choose JSON for transformation is the universality of JSON and the schemaless characteristics of JSON.
Bson mainly achieves the following three-point goals:
1. Faster traversal speed
In JSON format, too large a JSON structure can cause data traversal to be very slow. In JSON, to skip a document for data reading, this document needs to be scanned, and a cumbersome data structure should be matched, such as the matching of parentheses, and bson a big improvement to JSON is that it will have the length of each element of the JSON element in the head, This allows you to read directly to the specified point by reading the element length.
2. Easy to operate
For JSON, data storage is untyped, for example, if you want to modify a basic value, from 9 to 10, since a character becomes two, everything behind it may need to be moved backwards. Using Bson, you can specify this column as a number, then whether the number from 9 to 10 or 100, we are only stored in the number of the one on the change, does not cause the total length of the data to become larger. Of course, in MongoDB, if the number is increased from shaping to a long integer, it will cause the total length of the data to grow larger.
3. Added additional data types
JSON is a convenient format for data interchange, but its type is relatively limited. The Bson adds a "byte array" data type based on it. This makes binary storage no longer required to be Base64 converted before being stored as JSON. Greatly reduces the computational overhead and data size.
Of course, in some cases, Bson has no spatial advantage over JSON, such as {"Field": 7}, 7 using only one byte on the storage of JSON, and if using Bson, it is at least 4 bytes (32 bits)
Currently in 10gen, Bson has a codec pack for multiple languages. And it's all open source under Apache 2 license. And it's still growing further with MongoDB. About Bson,