1# basic_json::to_bson 2 3```cpp 4// (1) 5static std::vector<std::uint8_t> to_bson(const basic_json& j); 6 7// (2) 8static void to_bson(const basic_json& j, detail::output_adapter<std::uint8_t> o); 9static void to_bson(const basic_json& j, detail::output_adapter<char> o); 10``` 11 12BSON (Binary JSON) is a binary format in which zero or more ordered key/value pairs are stored as a single entity (a 13so-called document). 14 151. Returns a byte vector containing the BSON serialization. 162. Writes the BSON serialization to an output adapter. 17 18## Parameters 19 20`j` (in) 21: JSON value to serialize 22 23`o` (in) 24: output adapter to write serialization to 25 26## Return value 27 281. BSON serialization as byte vector 292. / 30 31## Exception safety 32 33Strong guarantee: if an exception is thrown, there are no changes in the JSON value. 34 35## Complexity 36 37Linear in the size of the JSON value `j`. 38 39## Example 40 41??? example 42 43 The example shows the serialization of a JSON value to a byte vector in BSON format. 44 45 ```cpp 46 --8<-- "examples/to_bson.cpp" 47 ``` 48 49 Output: 50 51 ```json 52 --8<-- "examples/to_bson.output" 53 ``` 54 55## Version history 56 57- Added in version 3.4.0. 58