Files
2026-10-27 12:14:00 +00:00

5.8 KiB

Binary Formats

Though JSON is a ubiquitous data format, it is not a very compact format suitable for data exchange, for instance, over a network. Hence, the library supports

to efficiently encode JSON values to byte vectors and to decode such vectors.

Comparison

Completeness

Format Serialization Deserialization
BJData complete incomplete: no column-major ND-arrays, no Draft 4 SoA/extension types
BON8 incomplete: no unsigned integers above int64 complete
BSON incomplete: top-level value must be an object incomplete, but all JSON types are supported
CBOR complete incomplete, but all JSON types are supported
MessagePack complete incomplete, but all JSON types are supported
UBJSON complete complete

Binary values

Format Binary values Binary subtypes
BJData supported (Draft 3 only) not supported
BON8 not supported not supported
BSON supported supported
CBOR supported supported
MessagePack supported supported
UBJSON not supported not supported

See binary values for more information.

Sizes

Format canada.json twitter.json citm_catalog.json jeopardy.json
BJData 53.2 % 91.1 % 78.1 % 96.6 %
BJData (size) 58.6 % 92.1 % 86.7 % 97.4 %
BJData (size+type) 58.6 % 92.1 % 86.5 % 97.4 %
BON8 50.5 % 83.8 % 63.5 % 87.5 %
BSON 85.8 % 95.2 % 95.8 % 106.7 %
CBOR 50.5 % 86.3 % 68.4 % 88.0 %
MessagePack 50.5 % 86.0 % 68.5 % 87.9 %
UBJSON 53.2 % 91.3 % 78.2 % 96.6 %
UBJSON (size) 58.6 % 92.3 % 86.8 % 97.4 %
UBJSON (size+type) 55.9 % 92.3 % 85.0 % 95.0 %

Size of each test file in each format, in percent of the minified JSON value; the smallest size per file is printed in bold. The (size) and (size+type) rows are written with the use_size and use_type options of to_bjdata and to_ubjson.

The table above as charts: size per base format relative to minified JSON (vertical line at 100 %); the smallest format per file is drawn in a stronger colour than the others. The size and size+type variants of BJData and UBJSON are omitted here; see the table.

See also