Docs Menu
Docs Home
/ / /
Java Sync
/ /

Document Data Format: BSON

On this page

  • Overview
  • BSON Data Format
  • MongoDB and BSON
  • Install the BSON Library

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 MongoDB Java 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 adds support for types including dates, different size integers, ObjectIds, and binary data. For a complete list of supported types, see the BSON Types server manual page.

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

The MongoDB Java 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, including:

For more information on using these object types, see our Documents guide.

These instructions show you how to add the BSON library as a dependency to your project. If you added the MongoDB Java 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 MongoDB Java driver as a dependency to your project, see the driver installation section of our Quick Start 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>
<version>4.7.2</version>
</dependency>
</dependencies>

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

dependencies {
compile 'org.mongodb:bson:4.7.2'
}

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 Formats