Docs Menu
Docs Home
/ / /
Kotlin Sync Driver
/

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 BSON to organize and store data, and how to install the BSON library independently of the Kotlin Sync 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, differently-sized integers (32-bit and 64-bit), ObjectIds, and binary data. For a complete list of supported types, see the BSON Types in the MongoDB Server documentation.

BSON is not human-readable, but you can use the BSON library to convert it to the human-readable JSON representation. You can read more about the relationship between these formats in the JSON and BSON guide on the MongoDB website.

You can work with BSON data in your Kotlin Sync driver application by using one of the following object types that implements the BSON interface:

  • Document (BSON library package)

  • BsonDocument (BSON library package)

  • RawBsonDocument (BSON library package)

  • JsonObject (BSON library package)

These instructions detail how to add the BSON library as a dependency to your project.

Note

If you have already added the Kotlin Sync driver as a dependency to your project, then you can skip this step. This is because the BSON library is already included as a required dependency of the driver.

For instructions on how to add the MongoDB Kotlin Sync Driver as a dependency to your project, see the driver installation section of our Get Started guide.

We recommend that you use the Maven or Gradle build automation tool to manage your Kotlin project's dependencies. The following instructions detail the dependency declarations for both Maven and Gradle:

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>5.2.0</version>
</dependency>
</dependencies>

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

dependencies {
implementation("org.mongodb:bson:5.2.0")
}

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

Back

Codecs