JSON for Modern C++ 2.1.1

allocator_type
array
array_t
at
at
at
at
at
at
back
back
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
begin
begin
boolean_t
cbegin
cend
clear
const_iterator
const_pointer
const_reference
const_reverse_iterator
count
crbegin
crend
detail::external_constructor
diff
difference_type
dump
emplace
emplace_back
empty
end
end
erase
erase
erase
erase
exception
find
find
flatten
from_cbor
from_msgpack
front
front
get
get
get
get
get
get_allocator
get_ptr
get_ptr
get_ref
get_ref
insert
insert
insert
insert
insert
insert
invalid_iterator
is_array
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_number_unsigned
is_object
is_primitive
is_string
is_structured
iterator
iterator_wrapper
iterator_wrapper
json_serializer
max_size
meta
number_float_t
number_integer_t
number_unsigned_t
object
object_t
operator value_t
operator ValueType
operator!=
operator!=
operator!=
operator+=
operator+=
operator+=
operator+=
operator<
operator<
operator<
operator<<
operator<<
operator<=
operator<=
operator<=
operator=
operator==
operator==
operator==
operator>
operator>
operator>
operator>=
operator>=
operator>=
operator>>
operator>>
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
other_error
out_of_range
parse
parse
parse
parse
parse
parse
parse_error
parse_event_t
parser_callback_t
patch
pointer
push_back
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
reverse_iterator
size
size_type
string_t
swap
swap
swap
swap
to_cbor
to_msgpack
type
type_error
type_name
unflatten
value
value
value
value
value_t
value_type
~basic_json
| ## ◆ from_cbor() template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
static basic_json nlohmann::basic_json::from_cbor | ( | const std::vector< uint8_t > & | v,
|  | const size_t | start_index = `0`
| ) |  |
| inline static
Deserializes a given byte vector v to a JSON value using the CBOR (Concise Binary Object Representation) serialization format. The library maps CBOR types to JSON value types as follows:
CBOR type | JSON value type | first byte
--- | --- | ---
Integer | number_unsigned | 0x00..0x17
Unsigned integer | number_unsigned | 0x18
Unsigned integer | number_unsigned | 0x19
Unsigned integer | number_unsigned | 0x1a
Unsigned integer | number_unsigned | 0x1b
Negative integer | number_integer | 0x20..0x37
Negative integer | number_integer | 0x38
Negative integer | number_integer | 0x39
Negative integer | number_integer | 0x3a
Negative integer | number_integer | 0x3b
Negative integer | number_integer | 0x40..0x57
UTF-8 string | string | 0x60..0x77
UTF-8 string | string | 0x78
UTF-8 string | string | 0x79
UTF-8 string | string | 0x7a
UTF-8 string | string | 0x7b
UTF-8 string | string | 0x7f
array | array | 0x80..0x97
array | array | 0x98
array | array | 0x99
array | array | 0x9a
array | array | 0x9b
array | array | 0x9f
map | object | 0xa0..0xb7
map | object | 0xb8
map | object | 0xb9
map | object | 0xba
map | object | 0xbb
map | object | 0xbf
False | `false` | 0xf4
True | `true` | 0xf5
Nill | `null` | 0xf6
Half-Precision Float | number_float | 0xf9
Single-Precision Float | number_float | 0xfa
Double-Precision Float | number_float | 0xfb
  Warning The mapping is incomplete in the sense that not all CBOR types can be converted to a JSON value. The following CBOR types are not supported and will yield parse errors (parse_error.112): byte strings (0x40..0x5f) date/time (0xc0..0xc1) bignum (0xc2..0xc3) decimal fraction (0xc4) bigfloat (0xc5) tagged items (0xc6..0xd4, 0xd8..0xdb) expected conversions (0xd5..0xd7) simple values (0xe0..0xf3, 0xf8) undefined (0xf7) CBOR allows map keys of any type, whereas JSON only allows strings as keys in object values. Therefore, CBOR maps with keys other than UTF-8 strings are rejected (parse_error.113). Note Any CBOR output created to_cbor can be successfully parsed by from_cbor. Parameters
  [in] | v | a byte vector in CBOR format
  [in] | start_index | the index to start reading from v (0 by default)
  Returns deserialized JSON value Exceptions
  parse_error.110 | if the given vector ends prematurely
  parse_error.112 | if unsupported features from CBOR were used in the given vector v or if the input is not valid CBOR
  parse_error.113 | if a string was expected as map key, but not found
  Complexity Linear in the size of the byte vector v. Example The example shows the deserialization of a byte vector in CBOR format to a JSON value. 1 #include "json.hpp" 2 #include <iomanip> // for std::setw 3 4 using json = nlohmann::json; 5 6 int main() 7 { 8 // create byte vector 9 std::vector<uint8_t> v = {0xa2, 0x67, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 10 0x74, 0xf5, 0x66, 0x73, 0x63, 0x68, 0x65, 0x6d, 11 0x61, 0x00 12 }; 13 14 // deserialize it with CBOR 15 json j = json::from_cbor(v); 16 17 // print the deserialized JSON value 18 std::cout << std::setw(2) << j << std::endl; 19 } nlohmann::json basic_json<> json default JSON class Definition: json.hpp:13933 nlohmann::basic_json::from_cbor static basic_json from_cbor(const std::vector< uint8_t > &v, const size_t start_index=0) create a JSON value from a byte vector in CBOR format Definition: json.hpp:9361 Output (play with this example online):
      {
        "compact": true,
        "schema": 0
      }
  The example code above can be translated with
      g++ -std=c++11 -Isrc doc/examples/from_cbor.cpp -o from_cbor
See also http://cbor.io to_cbor(const basic_json&) for the analogous serialization from_msgpack(const std::vector<uint8_t>&, const size_t) for the related MessagePack format Since version 2.0.9, parameter start_index since 2.1.1 Definition at line 9361 of file json.hpp.