The difference between Bson and JSON

Source: Internet
Author: User

Bson is currently mainly used in MongoDB, is the data storage format of MongoDB, Bson based on JSON format, the main reason to choose JSON for transformation is the universality of JSON and the characteristics of JSON schemaless.

Bson mainly achieve the following three points:

  1. Faster Traverse 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 before it can be done, requiring cumbersome data structure matching, such as the matching of parentheses.
A big improvement to JSON, however, is that it bson the length of each element of the JSON to the head of the element, so that you simply need to read the length of the element to read directly to the specified point.

  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 allows binary storage to be Base64 converted and then saved into JSON, greatly reducing the computational overhead and data size.

  

  Sum up

JSON is stored as a string in the data structure, and Bson is stored by structure.

Storage space on Bson>json

Operating speed on the Bson>json. For example, traversal lookup: JSON needs to sweep a string, and Bson can directly position it directly with the string length that precedes the string.

Modify the JSON to change because of the length of the string to move large, bson words because it is stored by the structure, so still occupy the same storage space, do not need to move.

The difference between Bson and JSON

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.