Data
What is BSON?
BSON (Binary JSON) is a binary serialization format for documents with a JSON-like structure. It also supports types that standard JSON does not, including dates, binary data, and ObjectId. MongoDB uses it widely, but BSON is not ordinary JSON text and requires a BSON-aware driver or tool.
When to choose this format
- Preserving types such as dates and binary values
- Working with drivers and tools that read and write BSON
When to avoid this format
- Reading or editing the contents in a plain text editor
- Sending directly to a JSON-only API or tool
Common uses
- Serializing MongoDB documents
- Exchanging documents between BSON-aware tools
Features
- Binary structure with document lengths and element type information
- Represents strings, numbers, arrays, and nested documents
- Supports additional types such as dates, binary data, and ObjectId
Advantages and disadvantages
Advantages
- Can preserve types that do not have direct equivalents in JSON
- MongoDB drivers and tools can process BSON documents
Disadvantages
- Not human-readable without a binary-aware tool
- Serialization details can vary by type and driver
- It is not always smaller or faster than JSON
Open and convert
How to open
Read it with mongorestore or a BSON-aware tool or library. To inspect its contents, convert BSON to Extended JSON or another readable representation. Do not edit the binary file in a text editor.
How to convert
When converting to JSON, dates, ObjectId, and binary values may need Extended JSON notation or application-specific representations because standard JSON has no matching types. If you need a round trip, choose a method that preserves type information and test it with real data.
Cautions
- A .bson file produced by mongodump may be part of a database backup rather than a standalone document. Check the full dump and its metadata.
- application/bson is used by implementations but is not an IANA-registered standard media type. Follow the recipient's requirements.
- Numbers, dates, UUIDs, and other values can be represented differently across language drivers. Validate values after conversion.
FAQ
Is BSON the same as JSON?
No. BSON stores JSON-like documents in binary and includes types such as dates and binary data that standard JSON does not have.
Can I rename a .bson file to .json?
No. Convert it with a BSON-aware tool and decide how to represent values that standard JSON cannot express.