1 # <small>nlohmann::basic_json::</small>to_ubjson
5 static std::vector<std::uint8_t> to_ubjson(const basic_json& j,
6 const bool use_size = false,
7 const bool use_type = false);
10 static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o,
11 const bool use_size = false, const bool use_type = false);
12 static void to_ubjson(const basic_json& j, detail::output_adapter<char> o,
13 const bool use_size = false, const bool use_type = false);
16 Serializes a given JSON value `j` to a byte vector using the UBJSON (Universal Binary JSON) serialization format. UBJSON
17 aims to be more compact than JSON itself, yet more efficient to parse.
19 1. Returns a byte vector containing the UBJSON serialization.
20 2. Writes the UBJSON serialization to an output adapter.
22 The exact mapping and its limitations is described on a [dedicated page](../../features/binary_formats/ubjson.md).
27 : JSON value to serialize
30 : output adapter to write serialization to
33 : whether to add size annotations to container types; optional, `#!cpp false` by default.
36 : whether to add type annotations to container types (must be combined with `#!cpp use_size = true`); optional,
37 `#!cpp false` by default.
41 1. UBJSON serialization as byte vector
46 Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
50 Linear in the size of the JSON value `j`.
56 The example shows the serialization of a JSON value to a byte vector in UBJSON format.
59 --8<-- "examples/to_ubjson.cpp"
65 --8<-- "examples/to_ubjson.output"
70 - Added in version 3.1.0.