Overview
Introduction
MongoDB stores and transmits documents as BSON, not JSON.
This tool shows what an XML document looks like encoded that way.
What Is XML to BSON Converter?
A converter that turns XML into JSON.
It then reuses this site's existing JSON to BSON Converter to encode that JSON as BSON bytes, shown as hex.
How XML to BSON Converter Works
XML is converted to JSON the same way the XML to JSON Converter does it.
Each key/value pair is then encoded with a BSON type byte and length-prefixed content: numbers become int32, int64, or double depending on their value, and strings, booleans, null, nested objects, and arrays each get their own BSON element type.
When To Use XML to BSON Converter
Use it to see what an XML document would look like as a MongoDB-style BSON document.
It's also useful when working with tooling that expects BSON input.
Often used alongside BSON to XML Converter, XML to Bencode Converter and XML to JSON Converter.
Features
Advantages
- Reuses the existing, tested JSON to BSON Converter rather than duplicating encoding logic.
- Runs entirely client-side.
- Automatically picks the right numeric BSON type (int32, int64, or double) for each value.
Limitations
- Covers a practical subset of BSON types (see the FAQ), not MongoDB-specific types like ObjectId or Date.
- 64-bit integers are approximated using JS's double-precision numbers, adequate for realistic data but not bit-exact for the full 64-bit integer range.
Examples
Best Practices & Notes
Best Practices
- Use BSON to XML Converter to check what a round trip does to your specific data.
- Reach for XML to BXML Converter instead if you specifically need to preserve XML's attribute/element distinction exactly.
- Treat this as a way to inspect BSON encoding, not as a substitute for a real MongoDB driver.
Developer Notes
This is a thin wrapper composing `xmlToJson` with the existing `jsonToBson` encoder in the JSON category; no BSON-encoding logic is duplicated here.
XML to BSON Converter Use Cases
- Seeing what an XML document looks like as a MongoDB-style BSON document
- Working with tooling that expects BSON input
- Teaching or demonstrating BSON's element-type encoding using a familiar XML document
Common Mistakes
- Expecting MongoDB-specific types like ObjectId or Date, they aren't produced by this converter.
- Assuming the hex output is directly usable as a MongoDB driver's binary payload without further handling.
Tips
- Use XML to BXML Converter instead if you want a binary encoding that preserves XML's attribute/element distinction exactly.
- Check the FAQ above if the output doesn't look like what you expected.