JSON, or JavaScript Object Notation, is a lightweight and easy-to-read format that is widely supported by many programming languages. It is also human-readable and easy to edit, making it a popular choice for storing configuration data, transmitting data over HTTP, and exchanging data between web services.

BSON, or Binary JSON, is a binary-encoded serialization format that is designed to be more efficient than JSON when working with large amounts of data. It supports more data types than JSON, including binary data, dates, and regular expressions, and can be up to 20-30% smaller in size than JSON.

BSON is often used in high-performance applications that require fast data access and efficient serialization and deserialization.

You should prefer JSON over BSON when:

  • The data is small and does not require special data types or binary data.

  • The data will be human-readable and easy to edit.

  • The application requires cross-platform support, as JSON is widely supported by many programming languages and platforms.

You should prefer BSON over JSON when:

  • The data is large and requires efficient serialization and deserialization.

  • The data contains special data types or binary data that cannot be represented in JSON.

  • The application requires high-performance data access, as BSON can be faster and more efficient than JSON.

In summary, JSON is a good choice for simple data structures and human-readable data, while BSON is a better choice for larger, more complex data structures that require high performance and efficient data access.

MongoDB JSON

MongoDB stores data in BSON format both internally, and over the network, but that doesn’t mean you can’t think of MongoDB as a JSON database. Anything you can represent in JSON can be natively stored in MongoDB, and retrieved just as easily in JSON.

When using the MongoDB driver for your favorite programming language, you work with the native data structures for that language. The driver will take care of converting the data to BSON and back when querying the database.