1 # <small>nlohmann::basic_json::</small>to_cbor
5 static std::vector<std::uint8_t> to_cbor(const basic_json& j);
8 static void to_cbor(const basic_json& j, detail::output_adapter<std::uint8_t> o);
9 static void to_cbor(const basic_json& j, detail::output_adapter<char> o);
12 Serializes a given JSON value `j` to a byte vector using the CBOR (Concise Binary Object Representation) serialization
13 format. CBOR is a binary serialization format which aims to be more compact than JSON itself, yet more efficient to
16 1. Returns a byte vector containing the CBOR serialization.
17 2. Writes the CBOR serialization to an output adapter.
19 The exact mapping and its limitations is described on a [dedicated page](../../features/binary_formats/cbor.md).
24 : JSON value to serialize
27 : output adapter to write serialization to
31 1. CBOR serialization as byte vector
36 Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
40 Linear in the size of the JSON value `j`.
46 The example shows the serialization of a JSON value to a byte vector in CBOR format.
49 --8<-- "examples/to_cbor.cpp"
55 --8<-- "examples/to_cbor.output"
60 - Added in version 2.0.9.
61 - Compact representation of floating-point numbers added in version 3.8.0.