mirror of
https://github.com/nlohmann/json.git
synced 2026-10-25 15:28:54 +00:00
- Make the iterator range illustrations legible in dark mode (prefers-color-scheme rules inside the SVGs). - Add a "Byte layout" section with a color-coded byte table to each binary format page (BJData, BON8, BSON, CBOR, MessagePack, UBJSON), and highlight the smallest size per file in the comparison table. - Add "See also" sections to the overview pages that lacked one. - Split the release notes into one page per release, grouped by minor version on the overview page, with an "API changes" section per release generated from the API pages' version histories (hooks/api_changes.py). - Fact-check the release notes and version histories against the release tags and correct wrong or misleading entries (e.g., json_serializer 2.1.0, merge_patch 3.1.0, items, count, operator[], to_bjdata, std::string_view key support). Signed-off-by: Niels Lohmann <mail@nlohmann.me>
3.9 KiB
3.9 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
- BJData (Binary JData),
- BON8 (Binary Object Notation 8),
- BSON (Binary JSON),
- CBOR (Concise Binary Object Representation),
- MessagePack, and
- UBJSON (Universal Binary JSON)
to efficiently encode JSON values to byte vectors and to decode such vectors.
Comparison
Completeness
| Format | Serialization | Deserialization |
|---|---|---|
| BJData | complete | complete |
| 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 | complete |
| UBJSON | complete | complete |
Binary values
| Format | Binary values | Binary subtypes |
|---|---|---|
| BJData | not supported | 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 % |
Sizes compared to minified JSON value; the smallest size per file is printed in bold.
See also
- Binary values - binary values and subtypes
- to_cbor / from_cbor, to_msgpack / from_msgpack, to_bson / from_bson, to_ubjson / from_ubjson, to_bjdata / from_bjdata, to_bon8 / from_bon8 - the conversion functions
- Parsing untrusted input
- SAX interface - decode binary formats without building a value