Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs Menu
Docs Home
/ /

Document Data Format: BSON

In this guide, you can learn about the BSON data format, how MongoDB uses it, and how to install the BSON library independently of the Kotlin driver.

BSON, or Binary JSON, is the data format that MongoDB uses to organize and store data. This data format includes all JSON data structure types and also supports other types, including dates, different size integers, ObjectId values, and binary data. For a complete list of supported types, see the BSON Types page in the MongoDB server manual.

The binary format is not human-readable, but you can use the Java BSON library to convert it to a JSON representation. To learn more about the relationship between these formats, see the JSON and BSON article.

The Kotlin driver, which uses the BSON library, allows you to work with BSON data by using one of the object types that implements the BSON interface. The following types implement the BSON interface:

This section shows how to add the BSON library as a dependency to your project. If you added the Kotlin driver as a dependency to your project, you can skip this step since the BSON library is already included as a required dependency of the driver. For instructions on how to add the Kotlin driver as a dependency to your project, see the Getting Started with the Kotlin Driver guide.

Tip

Bill of Materials

We recommend adding the JVM driver Bill of Materials (BOM) to your application to manage the versions of driver artifacts. This removes the need to specify a version for any individual package covered by the BOM, simplifying dependency management. To learn more, see the Getting Started with the Kotlin Driver guide.

We recommend that you use the Maven or Gradle build automation tool to manage your project's dependencies. Select from the following tabs to see the dependency declaration for that tool:

The following snippet shows the dependency declaration in the dependencies section of your pom.xml file.

<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
</dependency>
</dependencies>

The following snippet shows the dependency declaration in the dependencies object in your build.gradle file.

dependencies {
compile 'org.mongodb:bson'
}

If you are not using one of the preceding tools, you can include it in your project by downloading the JAR file directly from the sonatype repository.

Back

Data Classes

On this page