What is a .bson file?
Binary JSON · Data · MongoDB · 2009
BSON is a binary form of JSON used by MongoDB to store documents. It encodes the same field-and-value structure as JSON but in binary, adding data types JSON lacks, such as dates and raw binary.
What is a .bson file used for?
A BSON document begins with a 4-byte little-endian length rather than a fixed magic number, then its typed fields. It trades JSON's readability for faster parsing and richer types, which is why databases use it internally.
You rarely handle .bson files by hand; they come from MongoDB dumps (mongodump). Restore them with mongorestore, or read them with a BSON library.
How to open a .bson file
The .bson format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .bson file.
Windows
- MongoDB tools (mongorestore)
- Python (bson)
- MongoDB Compass
macOS
- MongoDB tools
- Python (bson)
- MongoDB Compass
Linux
- MongoDB tools
- Python (bson)
How to convert a .bson file
You can convert a .bson file to json using a conversion tool or the export menu of an app that opens it.
.bson file signature (magic bytes)
Programs recognise a .bson file by the bytes at the start of the file, not by its name. These are the signatures for BSON.
| Hex signature | Offset | Note |
|---|---|---|
| (no fixed signature) | 0 | no fixed magic; structure defined by a schema or header |
See the full magic-numbers reference for every format.
Frequently asked questions
What is a .bson file?
BSON is a binary form of JSON used by MongoDB to store documents. It encodes the same field-and-value structure as JSON but in binary, adding data types JSON lacks, such as dates and raw binary.
What is the difference between BSON and JSON?
BSON is binary and adds types JSON lacks (dates, binary, precise numbers) for faster machine reading. JSON is text and human-readable. MongoDB stores BSON internally.
How do I open a .bson file?
It usually comes from a MongoDB dump. Restore it with mongorestore, or read it with a BSON library such as Python's bson module.
Can I convert BSON to JSON?
Yes. MongoDB's bsondump tool, or a BSON library, converts a .bson document into readable JSON.
Related formats
Sources
Details on this page were checked against authoritative references: