__basic_json
allocator_type
array
array_t
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
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
begin
begin
boolean_t
cbegin
cend
clear
const_pointer
const_reference
count
crbegin
crend
difference_type
dump
empty
end
end
erase
erase
erase
erase
find
find
front
front
get
get
get_allocator
get_ptr
is_array
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_object
is_string
list_init_t
max_size
number_float_t
number_integer_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[]
parse
parse
parse_event_t
parser_callback_t
pointer
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
size
size_type
string_t
swap
swap
swap
swap
type
value_t
value_type
~basic_json

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 = int64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename ValueType >

nlohmann::basic_json::operator ValueType | ( |  | ) | const

inline

Implict type conversion between the JSON value and a compatible value. The call is realized by calling get() const.

Template Parameters

  ValueType | type compatible to the JSON value, for instance `int` for JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for JSON arrays

Returns
  copy of the JSON value, converted to type ValueType

Exceptions

  std::domain_error | in case passed type ValueType is incompatible to JSON, thrown by get() const

Complexity
  Linear in the size of the JSON value.

Example
  The example below shows serveral 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++ assiciative containers such as `std::unordered_map<std::string, json>`.
  #include <json.hpp>
  #include <unordered_map>
  using namespace nlohmann;
  int main()
  {
  // create a JSON value with different types
  json json_types =
  {
  {"boolean", true},
  {
  "number", {
  {"integer", 42},
  {"floating-point", 17.23}
  }
  },
  {"string", "Hello, world!"},
  {"array", {1, 2, 3, 4, 5}},
  {"null", nullptr}
  };
  // use implicit conversions
  bool v1 = json_types["boolean"];
  int v2 = json_types["number"]["integer"];
  short v3 = json_types["number"]["integer"];
  float v4 = json_types["number"]["floating-point"];
  int v5 = json_types["number"]["floating-point"];
  std::string v6 = json_types["string"];
  std::vector<short> v7 = json_types["array"];
  std::unordered_map<std::string, json> v8 = json_types;
  // print the conversion results
  std::cout << v1 << '\n';
  std::cout << v2 << ' ' << v3 << '\n';
  std::cout << v4 << ' ' << v5 << '\n';
  std::cout << v6 << '\n';
  for (auto i : v7)
  {
  std::cout << i << ' ';
  }
  std::cout << "\n\n";
  for (auto i : v8)
  {
  std::cout << i.first << ": " << i.second << '\n';
  }
  }
  nlohmann::basic_json
  a class to store JSON values
  Definition: json.hpp:121
  nlohmann
  namespace for Niels Lohmann
  Definition: json.hpp:56
  Output:

      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 -Isrc doc/examples/operator__ValueType.cpp -o operator__ValueType

  .