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
| ## ◆ basic_json() [7/10] template<class InputIT , typename std::enable_if< std::is_same< InputIT, typename basic_json_t::iterator >::value or std::is_same< InputIT, typename basic_json_t::const_iterator >::value, int >::type = 0>
nlohmann::basic_json::basic_json | ( | InputIT | first,
|  | InputIT | last
| ) |  |
| inline
  Constructs the JSON value with the contents of the range `[first, last)`. The semantics depends on the different types a JSON value can have: In case of a null type, invalid_iterator.206 is thrown. In case of other primitive types (number, boolean, or string), first must be `begin()` and last must be `end()`. In this case, the value is copied. Otherwise, invalid_iterator.204 is thrown. In case of structured types (array, object), the constructor behaves as similar versions for `std::vector` or `std::map`; that is, a JSON array or object is constructed from the values in the range. Template Parameters
  InputIT | an input iterator type (iterator or const_iterator)
  Parameters
  [in] | first | begin of the range to copy from (included)
  [in] | last | end of the range to copy from (excluded)
  Precondition Iterators first and last must be initialized. This precondition is enforced with an assertion (see warning). If assertions are switched off, a violation of this precondition yields undefined behavior. Range `[first, last)` is valid. Usually, this precondition cannot be checked efficiently. Only certain edge cases are detected; see the description of the exceptions below. A violation of this precondition yields undefined behavior. Warning A precondition is enforced with a runtime assertion that will result in calling `std::abort` if this precondition is not met. Assertions can be disabled by defining `NDEBUG` at compile time. See https://en.cppreference.com/w/cpp/error/assert for more information. Exceptions
  invalid_iterator.201 | if iterators first and last are not compatible (i.e., do not belong to the same JSON value). In this case, the range `[first, last)` is undefined.
  invalid_iterator.204 | if iterators first and last belong to a primitive type (number, boolean, or string), but first does not point to the first element any more. In this case, the range `[first, last)` is undefined. See example code below.
  invalid_iterator.206 | if iterators first and last belong to a null value. In this case, the range `[first, last)` is undefined.
  Complexity Linear in distance between first and last. Exception safety Strong guarantee: if an exception is thrown, there are no changes to any JSON value. Example The example below shows several ways to create JSON values by specifying a subrange with iterators. 1 #include <iostream> 2 #include <nlohmann/json.hpp> 3 4 using json = nlohmann::json; 5 6 int main() 7 { 8 // create JSON values 9 json j_array = {"alpha", "bravo", "charly", "delta", "easy"}; 10 json j_number = 42; 11 json j_object = {{"one", "eins"}, {"two", "zwei"}}; 12 13 // create copies using iterators 14 json j_array_range(j_array.begin() + 1, j_array.end() - 2); 15 json j_number_range(j_number.begin(), j_number.end()); 16 json j_object_range(j_object.begin(), j_object.find("two")); 17 18 // serialize the values 19 std::cout << j_array_range << '\n'; 20 std::cout << j_number_range << '\n'; 21 std::cout << j_object_range << '\n'; 22 23 // example for an exception 24 try 25 { 26 json j_invalid(j_number.begin() + 1, j_number.end()); 27 } 28 catch (json::invalid_iterator& e) 29 { 30 std::cout << e.what() << '\n'; 31 } 32 } Output (play with this example online):
      ["bravo","charly"]
      42
      {"one":"eins"}
      [json.exception.invalid_iterator.204] iterators out of range
  The example code above can be translated with
      g++ -std=c++11 -Isingle_include doc/examples/basic_json__InputIt_InputIt.cpp -o basic_json__InputIt_InputIt
Since version 1.0.0 Definition at line 17706 of file json.hpp.

nlohmann::basic_json::invalid_iterator
detail::invalid_iterator invalid_iterator
exception indicating errors with iterators
Definition: json.hpp:16043
nlohmann::json
basic_json<> json
default JSON class
Definition: json.hpp:2774