1# <small>nlohmann::basic_json::</small>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 18The exact mapping and its limitations is described on a [dedicated page](../../features/binary_formats/bson.md). 19 20## Parameters 21 22`j` (in) 23: JSON value to serialize 24 25`o` (in) 26: output adapter to write serialization to 27 28## Return value 29 301. BSON serialization as byte vector 312. (none) 32 33## Exception safety 34 35Strong guarantee: if an exception is thrown, there are no changes in the JSON value. 36 37## Complexity 38 39Linear in the size of the JSON value `j`. 40 41## Examples 42 43??? example 44 45 The example shows the serialization of a JSON value to a byte vector in BSON format. 46 47 ```cpp 48 --8<-- "examples/to_bson.cpp" 49 ``` 50 51 Output: 52 53 ```json 54 --8<-- "examples/to_bson.output" 55 ``` 56 57## Version history 58 59- Added in version 3.4.0. 60