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
| ## ◆ at() [6/6] 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>
const_reference nlohmann::basic_json::at | ( | const json_pointer & | ptr | ) | const
| inline
  Returns a const reference to the element at with specified JSON pointer ptr, with bounds checking. Parameters
  [in] | ptr | JSON pointer to the desired element
  Returns reference to the element pointed to by ptr Exceptions
  parse_error.106 | if an array index in the passed JSON pointer ptr begins with '0'. See example below.
  parse_error.109 | if an array index in the passed JSON pointer ptr is not a number. See example below.
  out_of_range.401 | if an array index in the passed JSON pointer ptr is out of range. See example below.
  out_of_range.402 | if the array index '-' is used in the passed JSON pointer ptr. As `at` provides checked access (and no elements are implicitly inserted), the index '-' is always invalid. See example below.
  out_of_range.404 | if the JSON pointer ptr can not be resolved. See example below.
  Exception safety Strong guarantee: if an exception is thrown, there are no changes in the JSON value. Complexity Constant. Since version 2.0.0 Example The behavior is shown in the example. 1 #include "json.hpp" 2 3 using json = nlohmann::json; 4 5 int main() 6 { 7 // create a JSON value 8 const json j = 9 { 10 {"number", 1}, {"string", "foo"}, {"array", {1, 2}} 11 }; 12 13 // read-only access 14 15 // output element with JSON pointer "/number" 16 std::cout << j.at("/number"_json_pointer) << '\n'; 17 // output element with JSON pointer "/string" 18 std::cout << j.at("/string"_json_pointer) << '\n'; 19 // output element with JSON pointer "/array" 20 std::cout << j.at("/array"_json_pointer) << '\n'; 21 // output element with JSON pointer "/array/1" 22 std::cout << j.at("/array/1"_json_pointer) << '\n'; 23 24 // out_of_range.109 25 try 26 { 27 // try to use an array index that is not a number 28 json::const_reference ref = j.at("/array/one"_json_pointer); 29 } 30 catch (json::parse_error& e) 31 { 32 std::cout << e.what() << '\n'; 33 } 34 35 // out_of_range.401 36 try 37 { 38 // try to use a an invalid array index 39 json::const_reference ref = j.at("/array/4"_json_pointer); 40 } 41 catch (json::out_of_range& e) 42 { 43 std::cout << e.what() << '\n'; 44 } 45 46 // out_of_range.402 47 try 48 { 49 // try to use the array index '-' 50 json::const_reference ref = j.at("/array/-"_json_pointer); 51 } 52 catch (json::out_of_range& e) 53 { 54 std::cout << e.what() << '\n'; 55 } 56 57 // out_of_range.404 58 try 59 { 60 // try to use a JSON pointer that cannot be resolved 61 json::const_reference ref = j.at("/number/foo"_json_pointer); 62 } 63 catch (json::out_of_range& e) 64 { 65 std::cout << e.what() << '\n'; 66 } 67 } nlohmann::json basic_json<> json default JSON class Definition: json.hpp:13933 nlohmann::basic_json::at reference at(size_type idx) access specified array element with bounds checking Definition: json.hpp:3780 nlohmann::basic_json::const_reference const value_type & const_reference the type of an element const reference Definition: json.hpp:1346 nlohmann::basic_json::out_of_range detail::out_of_range out_of_range exception indicating access out of the defined range Definition: json.hpp:1324 nlohmann::basic_json::parse_error detail::parse_error parse_error exception indicating a parse error Definition: json.hpp:1318 Output (play with this example online):
      1
      "foo"
      [1,2]
      2
      [json.exception.parse_error.109] parse error: array index 'one' is not a number
      [json.exception.out_of_range.401] array index 4 is out of range
      [json.exception.out_of_range.402] array index '-' (2) is out of range
      [json.exception.out_of_range.404] unresolved reference token 'foo'
  The example code above can be translated with
      g++ -std=c++11 -Isrc doc/examples/at_json_pointer_const.cpp -o at_json_pointer_const
Definition at line 13369 of file json.hpp.