BSON is a binary storage format for JSON data. The BSON specification is located at http://bsonspec.org/. BSON maintains the overall structure of JSON text data, but it encodes data type, variable length, and nesting information. It is designed to be lightweight so there is little additional overhead as compared to text-based JSON in terms of storage. It is easily traversable and efficient in terms of the time needed to convert to and from BSON.
- Object
- Array
- String
- Number
- null
- Boolean
- Binary data
- Floating point
- Date
- Timestamp
- When exchanging data with MongoDB
- When retrieval of portions of the document is more important than insertion time
- When compactness of storage is not as important as retrieval speed
BSON encodes strings in the UTF-8 character set. The character set for BSON data when it is imported or exported as text is UNICODE.
Numeric types are always serialized in little-endian format. If data is imported to or exported from the database in the BSON format (via constructor/instance methods or cast expressions), it is expected to be in this format.