Overview
Introduction
UBJSON exists for exactly the situations where JSON's text format is too slow or too large to parse, embedded systems, game save files, high-throughput binary protocols, while keeping JSON's exact data model intact.
This tool encodes a JSON value into UBJSON bytes and shows the result as a hex dump so you can inspect exactly how each value gets typed and packed.
What Is JSON to UBJSON Converter?
A UBJSON encoder that converts a JSON value into UBJSON's binary type-tagged format: each value is prefixed with a single-byte type marker (like S for string, i for int8, [ for array start) followed by its binary payload.
It uses UBJSON's basic container format rather than the optimized (strongly-typed, fixed-length) variant, prioritizing straightforward, universally-readable output.
How JSON to UBJSON Converter Works
The encoder recursively walks the parsed JSON value: strings become a length-prefixed UBJSON string type, whole numbers get the smallest integer type that fits their magnitude, non-integer numbers become float64, and objects/arrays become [ / { containers holding their encoded members, each terminated by ] or }.
The result is a sequence of raw bytes, which the tool renders as a space-separated hex dump (two hex characters per byte) since browsers can't display raw binary as readable text.
When To Use JSON to UBJSON Converter
Use it when testing a UBJSON parser or embedded system's deserializer and you need known-correct UBJSON bytes generated from a specific JSON value.
It's also useful for learning UBJSON's type-tagged binary layout by comparing a JSON value against its encoded hex bytes.
Often used alongside UBJSON to JSON Converter, JSON to MessagePack Converter and JSON to BSON Converter.
Features
Advantages
- Picks the smallest integer type for each number, matching how real UBJSON packers minimize output size.
- Preserves JSON's exact data model, no extra types to reconcile, unlike some other binary formats.
- Runs entirely client-side, so no data being encoded ever leaves the browser.
Limitations
- Uses UBJSON's basic container format only; the optimized (strongly-typed, length-prefixed) container variant isn't produced.
- Output is a hex string for inspection, not a downloadable binary .ubj file.
Examples
Best Practices & Notes
Best Practices
- Use the hex dump to spot-check individual type markers against the UBJSON spec when learning the format.
- Expect the smallest-fitting integer type per value, don't assume every number encodes the same number of bytes.
- Cross-check against UBJSON to JSON to confirm a round trip preserves your data exactly.
Developer Notes
The encoder chooses each integer's UBJSON type by checking its magnitude against int8/uint8/int16/int32/int64 ranges in order and picking the first that fits, the same size-minimization strategy real UBJSON packers use, rather than always emitting a fixed-width type regardless of value.
JSON to UBJSON Converter Use Cases
- Generating a known-correct UBJSON fixture for testing a parser or embedded deserializer
- Learning UBJSON's type-tagged binary layout by comparing it against equivalent JSON
- Debugging a UBJSON encoder/decoder implementation by comparing hex output byte-by-byte
Common Mistakes
- Expecting the optimized (strongly-typed) container format; this encoder produces the basic, per-element-tagged format only.
- Assuming every integer encodes to the same number of bytes; the type is chosen per-value based on magnitude.
- Trying to save the hex text directly as a binary file without converting it back to raw bytes first.
Tips
- Pair with UBJSON to JSON to verify the encoding round-trips correctly.
- If comparing against another UBJSON implementation's output, check whether it uses the optimized container format, since byte layouts will differ from this basic-format encoder.