BSON ↔ JSON Converter

Converts a JSON object to BSON hexadecimal bytes with encode, or a complete BSON hexadecimal document to JSON with decode. Lengths and numeric fields use little-endian order. Supported values are strings, booleans, null, finite doubles, int32, int64, embedded documents and arrays.

Loading tool module...

About this bson ↔ json converter

BSON ↔ JSON Converter — browser-based utility.

How this tool works

Converts a JSON object to BSON hexadecimal bytes with encode, or a complete BSON hexadecimal document to JSON with decode. Lengths and numeric fields use little-endian order. Supported values are strings, booleans, null, finite doubles, int32, int64, embedded documents and arrays.

  1. Paste {"name":"CZOA","ok":true} into Input.
  2. Set Second input / expression to encode, then press Run locally.
  3. Compare Output with the 25-byte example. For the reverse conversion, paste those hex bytes into Input, set the second field to decode and run again.

Worked example

Scenario: Encode a string and boolean into a complete BSON document, then decode the same bytes.

Sample input:

{"name":"CZOA","ok":true}

Processing: Converts a JSON object to BSON hexadecimal bytes with encode, or a complete BSON hexadecimal document to JSON with decode. Lengths and numeric fields use little-endian order. Supported values are strings, booleans, null, finite doubles, int32, int64, embedded documents and arrays.; encode

Illustrative output:

19 00 00 00 02 6e 61 6d 65 00 05 00 00 00 43 5a 4f 41 00 08 6f 6b 00 01 00

Limits and verification

The BSON document limit is 16 MiB, with at most 100 document levels including the root. Hex input permits ASCII spaces, tabs and line breaks. Duplicate fields, malformed lengths, invalid UTF-8, invalid booleans, nonsequential array indexes and trailing data are rejected. ObjectId, dates, binary data, regex and Decimal128 BSON types are not supported. Encoding accepts safe JSON integers from −9007199254740991 to 9007199254740991: int32 when possible, otherwise int64. Fractional values use binary64 and its rounding. Nonzero underflow and non-finite numbers are rejected. Decoded int64 values outside the safe range become decimal strings; re-encoding those strings produces BSON strings, so the original int64 type is not preserved. JSON conversion can normalize number spelling, object-field order and integer storage width; a round-trip need not reproduce identical BSON bytes. This is not a MongoDB Extended JSON interpreter. Objects containing $oid, $date or $numberLong are ordinary nested JSON objects; those names do not construct special BSON values. The displayed sample encodes {"name":"CZOA","ok":true} as a 25-byte BSON document. To reverse it, paste the complete hex result and set the second field to decode.

Examples demonstrate an expected workflow; they do not prove every input or every branch of an external specification. Check important results with an independent source before using them for money, security, compliance, safety, or irreversible file changes.

Browser processing boundary

Tool input is processed by code running in the browser and is not intentionally sent to a CZOA processing API. The page can still request ordinary site assets, analytics, or advertising when those services are enabled. Browser extensions and managed-device software remain outside this tool's control.

Relevant references

These references govern or help explain the format, protocol, or calculation used here. Listing a reference does not claim certification or complete implementation of every optional feature.

Content owner: CZOA Tools · Last reviewed: 2026-09-15 · Review methodology

How to use it

  1. Paste {"name":"CZOA","ok":true} into Input.
  2. Set Second input / expression to encode, then press Run locally.
  3. Compare Output with the 25-byte example. For the reverse conversion, paste those hex bytes into Input, set the second field to decode and run again.

Frequently asked questions

Which BSON conversion does this page perform?+

It either encodes supported JSON values into one BSON document rendered as hexadecimal, or decodes one complete hexadecimal BSON document. BSON lengths and numeric fields are read and written little-endian.

Which BSON types and integer boundary does the converter expose?+

It accepts strings, booleans, null, finite doubles, int32, int64, nested documents, and arrays. Safe JSON integers select int32 or int64; a decoded int64 beyond JavaScript safe precision is rendered as a decimal string.

Is BSON decode then encode byte-preserving?+

No. Re-encoding a decimal string that came from an unsafe int64 creates a BSON string. JSON number spelling, field order, and integer widths can also normalize, so this is not a byte-preserving BSON round trip.

What malformed BSON does the decoder reject?+

It rejects malformed lengths, invalid UTF-8, duplicate field names, nonsequential array indexes, and trailing bytes. A document is capped at 16 MiB and 100 document levels; ObjectId, dates, binary, regex, and Decimal128 are outside this subset.