1# basic_json::from_cbor 2 3```cpp 4// (1) 5template<typename InputType> 6static basic_json from_cbor(InputType&& i, 7 const bool strict = true, 8 const bool allow_exceptions = true, 9 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error); 10 11// (2) 12template<typename IteratorType> 13static basic_json from_cbor(IteratorType first, IteratorType last, 14 const bool strict = true, 15 const bool allow_exceptions = true, 16 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error); 17``` 18 19Deserializes a given input to a JSON value using the CBOR (Concise Binary Object Representation) serialization format. 20 211. Reads from a compatible input. 222. Reads from an iterator range. 23 24## Template parameters 25 26`InputType` 27: A compatible input, for instance: 28 29 - an `std::istream` object 30 - a `FILE` pointer 31 - a C-style array of characters 32 - a pointer to a null-terminated string of single byte characters 33 - an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators. 34 35`IteratorType` 36: a compatible iterator type 37 38## Parameters 39 40`i` (in) 41: an input in CBOR format convertible to an input adapter 42 43`first` (in) 44: iterator to start of the input 45 46`last` (in) 47: iterator to end of the input 48 49`strict` (in) 50: whether to expect the input to be consumed until EOF (`#!cpp true` by default) 51 52`allow_exceptions` (in) 53: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default) 54 55`tag_handler` (in) 56: how to treat CBOR tags (optional, `error` by default); see [`cbor_tag_handler_t`](cbor_tag_handler_t.md) for more 57 information 58 59## Return value 60 61deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be 62`value_t::discarded`. The latter can be checked with [`is_discarded`](is_discarded.md). 63 64## Exception safety 65 66Strong guarantee: if an exception is thrown, there are no changes in the JSON value. 67 68## Complexity 69 70Linear in the size of the input. 71 72## Example 73 74??? example 75 76 The example shows the deserialization of a byte vector in CBOR format to a JSON value. 77 78 ```cpp 79 --8<-- "examples/from_cbor.cpp" 80 ``` 81 82 Output: 83 84 ```json 85 --8<-- "examples/from_cbor.output" 86 ``` 87 88## Version history 89 90- Added in version 2.0.9. 91- Parameter `start_index` since version 2.1.1. 92- Changed to consume input adapters, removed `start_index` parameter, and added `strict` parameter in version 3.0.0. 93- Added `allow_exceptions` parameter in version 3.2.0. 94- Added `tag_handler` parameter in version 3.9.0. 95