JSON for Modern C++ 3.7.3

accept
accept
accept
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
basic_json
basic_json
begin
begin
binary
binary
binary
binary
binary_t
boolean_t
cbegin
cend
clear
const_iterator
const_pointer
const_reference
const_reverse_iterator
contains
contains
count
crbegin
crend
detail::external_constructor
diff
difference_type
dump
emplace
emplace_back
empty
end
end
erase
erase
erase
erase
error_handler_t
exception
find
find
flatten
from_bson
from_bson
from_bson
from_cbor
from_cbor
from_cbor
from_msgpack
from_msgpack
from_msgpack
from_ubjson
from_ubjson
from_ubjson
front
front
get
get
get
get
get
get
get_allocator
get_binary
get_binary
get_ptr
get_ptr
get_ref
get_ref
get_to
get_to
initializer_list_t
input_format_t
insert
insert
insert
insert
insert
insert
insert_iterator
invalid_iterator
is_array
is_binary
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
items
items
iterator
iterator_wrapper
iterator_wrapper
json_pointer
json_sax_t
json_serializer
max_size
merge_patch
meta
number_float_t
number_integer_t
number_unsigned_t
object
object_comparator_t
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[]
other_error
out_of_range
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
sax_parse
sax_parse
sax_parse
size
size_type
string_t
swap
swap
swap
swap
swap
swap
to_bson
to_bson
to_bson
to_cbor
to_cbor
to_cbor
to_msgpack
to_msgpack
to_msgpack
to_ubjson
to_ubjson
to_ubjson
type
type_error
type_name
unflatten
update
update
value
value
value
value
value_t
value_type
~basic_json
| ## ◆ get_to() [2/2] template<typename ValueType , detail::enable_if_t< not detail::is_basic_json< ValueType >::value and detail::has_from_json< basic_json_t, ValueType >::value, int > = 0>
ValueType& nlohmann::basic_json::get_to | ( | ValueType & | v | ) | const
| inlinenoexcept
  Explicit type conversion between the JSON value and a compatible value. The value is filled into the input parameter by calling the json_serializer<ValueType> `from_json()` method. The function is equivalent to executing ValueType v; JSONSerializer<ValueType>::from_json(*this, v); This overloads is chosen if: ValueType is not basic_json, json_serializer<ValueType> has a `from_json()` method of the form `void from_json(const basic_json&, ValueType&)`, and Template Parameters
  ValueType | the input parameter type.
  Returns the input parameter, allowing chaining calls. Exceptions
  what | json_serializer<ValueType> `from_json()` method throws
  Example The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers, (2) A JSON array can be converted to a standard `std::vector<short>`, (3) A JSON object can be converted to C++ associative containers such as `std::unordered_map<std::string, json>`. 1 #include <iostream> 2 #include <unordered_map> 3 #include <nlohmann/json.hpp> 4 5 using json = nlohmann::json; 6 7 int main() 8 { 9 // create a JSON value with different types 10 json json_types = 11 { 12 {"boolean", true}, 13 { 14 "number", { 15 {"integer", 42}, 16 {"floating-point", 17.23} 17 } 18 }, 19 {"string", "Hello, world!"}, 20 {"array", {1, 2, 3, 4, 5}}, 21 {"null", nullptr} 22 }; 23 24 bool v1; 25 int v2; 26 short v3; 27 float v4; 28 int v5; 29 std::string v6; 30 std::vector<short> v7; 31 std::unordered_map<std::string, json> v8; 32 33 34 // use explicit conversions 35 json_types["boolean"].get_to(v1); 36 json_types["number"]["integer"].get_to(v2); 37 json_types["number"]["integer"].get_to(v3); 38 json_types["number"]["floating-point"].get_to(v4); 39 json_types["number"]["floating-point"].get_to(v5); 40 json_types["string"].get_to(v6); 41 json_types["array"].get_to(v7); 42 json_types.get_to(v8); 43 44 // print the conversion results 45 std::cout << v1 << '\n'; 46 std::cout << v2 << ' ' << v3 << '\n'; 47 std::cout << v4 << ' ' << v5 << '\n'; 48 std::cout << v6 << '\n'; 49 50 for (auto i : v7) 51 { 52 std::cout << i << ' '; 53 } 54 std::cout << "\n\n"; 55 56 for (auto i : v8) 57 { 58 std::cout << i.first << ": " << i.second << '\n'; 59 } 60 } Output (play with this example online):
      1
      42 42
      17.23 17
      Hello, world!
      1 2 3 4 5

      string: "Hello, world!"
      number: {"floating-point":17.23,"integer":42}
      null: null
      boolean: true
      array: [1,2,3,4,5]
  The example code above can be translated with
      g++ -std=c++11 -Isingle_include doc/examples/get_to.cpp -o get_to
Since version 3.3.0 Definition at line 18805 of file json.hpp.

nlohmann::json
basic_json<> json
default JSON class
Definition: json.hpp:2774