What is BSON?

BSON (or Binary JSON) is a binary encoding of JSON-like documents that MongoDB uses to store information in documents. It adds support for Date and binary (BinData) data type that aren’t supported in JSON.

BSON was designed to have the following three characteristics:

  • Lightweight: Keeping spatial overhead to a minimum is important for any data representation format, especially when used over the network.
  • Traversable: BSON is designed to be traversed easily. This is a vital property in its role as the primary data representation for MongoDB.
  • Efficient: Encoding data to BSON and decoding from BSON can be performed very quickly in most languages due to the use of C data types.

BSON is designed to be efficient in space, but in many 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 prefixes, that make it easy and fast to traverse.

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.


Leave a Reply

Your email address will not be published. Required fields are marked *