# 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 - [BJData](bjdata.md) (Binary JData), - [BON8](bon8.md) (Binary Object Notation 8), - [BSON](bson.md) (Binary JSON), - [CBOR](cbor.md) (Concise Binary Object Representation), - [MessagePack](messagepack.md), and - [UBJSON](ubjson.md) (Universal Binary JSON) 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](../binary_values.md) 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`](../../api/basic_json/to_bjdata.md) and [`to_ubjson`](../../api/basic_json/to_ubjson.md).

Size of canada.json in each binary format relative to minified J​SON B​JData 53.2 %; B​ON8 50.5 %; B​SON 85.8 %; C​BOR 50.5 %; MessagePack 50.5 %; U​BJSON 53.2 %. Smallest: B​ON8 and C​BOR and MessagePack. canada.json 0 % 50 % B​JData canada.json, B​JData: 53.2 % of minified J​SON B​ON8 canada.json, B​ON8: 50.5 % of minified J​SON (smallest) B​SON canada.json, B​SON: 85.8 % of minified J​SON C​BOR canada.json, C​BOR: 50.5 % of minified J​SON (smallest) MessagePack canada.json, MessagePack: 50.5 % of minified J​SON (smallest) U​BJSON canada.json, U​BJSON: 53.2 % of minified J​SON minified J​SON = 100 % 100 % 53.2 % 50.5 % 85.8 % 50.5 % 50.5 % 53.2 %
Size of twitter.json in each binary format relative to minified J​SON B​JData 91.1 %; B​ON8 83.8 %; B​SON 95.2 %; C​BOR 86.3 %; MessagePack 86 %; U​BJSON 91.3 %. Smallest: B​ON8. twitter.json 0 % 50 % B​JData twitter.json, B​JData: 91.1 % of minified J​SON B​ON8 twitter.json, B​ON8: 83.8 % of minified J​SON (smallest) B​SON twitter.json, B​SON: 95.2 % of minified J​SON C​BOR twitter.json, C​BOR: 86.3 % of minified J​SON MessagePack twitter.json, MessagePack: 86 % of minified J​SON U​BJSON twitter.json, U​BJSON: 91.3 % of minified J​SON minified J​SON = 100 % 100 % 91.1 % 83.8 % 95.2 % 86.3 % 86.0 % 91.3 %
Size of citm_catalog.json in each binary format relative to minified J​SON B​JData 78.1 %; B​ON8 63.5 %; B​SON 95.8 %; C​BOR 68.4 %; MessagePack 68.5 %; U​BJSON 78.2 %. Smallest: B​ON8. citm_catalog.json 0 % 50 % B​JData citm_catalog.json, B​JData: 78.1 % of minified J​SON B​ON8 citm_catalog.json, B​ON8: 63.5 % of minified J​SON (smallest) B​SON citm_catalog.json, B​SON: 95.8 % of minified J​SON C​BOR citm_catalog.json, C​BOR: 68.4 % of minified J​SON MessagePack citm_catalog.json, MessagePack: 68.5 % of minified J​SON U​BJSON citm_catalog.json, U​BJSON: 78.2 % of minified J​SON minified J​SON = 100 % 100 % 78.1 % 63.5 % 95.8 % 68.4 % 68.5 % 78.2 %
Size of jeopardy.json in each binary format relative to minified J​SON B​JData 96.6 %; B​ON8 87.5 %; B​SON 106.7 %; C​BOR 88 %; MessagePack 87.9 %; U​BJSON 96.6 %. Smallest: B​ON8. jeopardy.json 0 % 50 % B​JData jeopardy.json, B​JData: 96.6 % of minified J​SON B​ON8 jeopardy.json, B​ON8: 87.5 % of minified J​SON (smallest) B​SON jeopardy.json, B​SON: 106.7 % of minified J​SON C​BOR jeopardy.json, C​BOR: 88 % of minified J​SON MessagePack jeopardy.json, MessagePack: 87.9 % of minified J​SON U​BJSON jeopardy.json, U​BJSON: 96.6 % of minified J​SON minified J​SON = 100 % 100 % 96.6 % 87.5 % 106.7 % 88.0 % 87.9 % 96.6 %

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 - [`cbor_tag_handler_t`](../../api/basic_json/cbor_tag_handler_t.md) - how CBOR tags are handled when parsing - [`JSON_STRICT_BINARY_UTF8`](../../api/macros/json_strict_binary_utf8.md) - reject ill-formed UTF-8 in strings - [Binary values](../binary_values.md) - binary values and subtypes - [`to_cbor`](../../api/basic_json/to_cbor.md) - / [`from_cbor`](../../api/basic_json/from_cbor.md), [`to_msgpack`](../../api/basic_json/to_msgpack.md) / [`from_msgpack`](../../api/basic_json/from_msgpack.md), [`to_bson`](../../api/basic_json/to_bson.md) / [`from_bson`](../../api/basic_json/from_bson.md), [`to_ubjson`](../../api/basic_json/to_ubjson.md) / [`from_ubjson`](../../api/basic_json/from_ubjson.md), [`to_bjdata`](../../api/basic_json/to_bjdata.md) / [`from_bjdata`](../../api/basic_json/from_bjdata.md), [`to_bon8`](../../api/basic_json/to_bon8.md) / [`from_bon8`](../../api/basic_json/from_bon8.md) - the conversion functions - [Parsing untrusted input](../parsing/untrusted_input.md) - harden an application that parses untrusted binary data - [SAX interface](../parsing/sax_interface.md) - decode binary formats without building a value