Conflicts: doc/mkdocs/docs/api/basic_json/index.md doc/mkdocs/docs/features/binary_formats/bson.md doc/mkdocs/docs/features/binary_formats/index.md doc/mkdocs/mkdocs.yml include/nlohmann/json.hpp single_include/nlohmann/json.hpp
3.4 KiB
3.4 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
- BSON (Binary JSON),
- CBOR (Concise Binary Object Representation),
- MessagePack, and
- UBJSON (Universal Binary JSON)
- BON8
to efficiently encode JSON values to byte vectors and to decode such vectors.
Comparison
Completeness
| Format | Serialization | Deserialization |
|---|---|---|
| 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 |
| BON8 | complete | not yet implemented |
Binary values
| Format | Binary values | Binary subtypes |
|---|---|---|
| BSON | supported | supported |
| CBOR | supported | supported |
| MessagePack | supported | supported |
| UBJSON | not supported | not supported |
| BON8 | not supported | not supported |
See binary values for more information.
Sizes
| Format | canada.json | twitter.json | citm_catalog.json | jeopardy.json | sample.json |
|---|---|---|---|---|---|
| BSON | 85,8 % | 95,2 % | 95,8 % | 106,7 % (1) | N/A (2) |
| CBOR | 50,5 % | 86,3 % | 68,4 % | 88,0 % | 87,2 % |
| MessagePack | 50,6 % | 86,0 % | 68,5 % | 87,9 % | 87,2 % |
| UBJSON | 53,2 % | 91,3 % | 78,2 % | 96,6 % | 88,2 % |
| UBJSON (size) | 58,6 % | 92,3 % | 86,8 % | 97,4 % | 89,3 % |
| UBJSON (size+type) | 55,9 % | 92,3 % | 85,0 % | 95,0 % | 89,5 % |
| BON8 | 50,5 % | 83,8 % | 63,5 % | 87,5 % | 85,6 % |
Sizes compared to minified JSON value.
Notes:
- (1) The JSON value is an array that needed to be wrapped in an object to be processed by BSON. We used an empty object key for minimal overhead.
- (2) The JSON value contained a string with code point
U+0000which cannot be represented by BSON.
The JSON files are part of the nlohmann/json_test_data repository.