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.
About this 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 Transforms and validates developer data structures locally, preventing confidential payload exposure during data wrangling.
Syntax parsing & data transformation logic
Implements deterministic lexical tokenization and lossless Abstract Syntax Tree (AST) reconstruction for structured data serialization formats, adhering strictly to RFC 8259, ECMA-404, YAML 1.2, RFC 4180 CSV, and the JSON5 draft specification. The custom lexical scanner preserves 64-bit unsigned and signed integers exceeding IEEE 754 double-precision safe limits (numbers outside [-(2^53 - 1), 2^53 - 1]) as exact text tokens, preventing catastrophic rounding of database primary keys and cryptographic nonces. Recursive descent parsing is bounded by an explicit maximum nesting depth to eliminate call stack exhaustion attacks ($O(N)$ depth guard).
Worked conversion & output example
Scenario: Encode a string and boolean into a complete BSON document, then decode the same bytes.
Sample input:
Second field:
Processing: The client-side engine parses the provided input, executes the transformation routine, and outputs the result in real time.
Illustrative output:
Syntax constraints & input size limits
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.
Data conversions and formatting in BSON ↔ JSON Converter reflect standard structured syntax. Verify parsed outputs against your target runtime before deployment.
Local client execution boundary
Data parsing and transformations in BSON ↔ JSON Converter execute in the local browser tab without remote data transmission.
Data format specifications & language standards
Data interchange formats and language grammar specifications:
- BSON Specification 1.1 (supported JSON-compatible types only)
- RFC 8259 (JSON)
- IEEE 754 binary64; UTF-8
BSON ↔ JSON Converter verification · Audit standards
How to use it
- Paste {"name":"CZOA","ok":true} into Input.
- Set Second input / expression to encode, then press Run locally.
- 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.
