The difference between Bson and JSON

Source: Internet
Author: User

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,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.