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
const_reverse_iterator
count
crbegin
crend
difference_type
dump
empty
end
end
erase
erase
erase
erase
find
find
front
front
get
get
get
get_allocator
get_ptr
get_ptr
get_ref
get_ref
insert
insert
insert
insert
insert
is_array
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_object
is_primitive
is_string
is_structured
iterator_wrapper
iterator_wrapper
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[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
parse
parse
parse
parse_event_t
parser_callback_t
pointer
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
reverse_iterator
size
size_type
string_t
swap
swap
swap
swap
type
value
value
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<class CompatibleArrayType , typename std::enable_if< not std::is_same< CompatibleArrayType, typename basic_json_t::iterator >::value and not std::is_same< CompatibleArrayType, typename basic_json_t::const_iterator >::value and not std::is_same< CompatibleArrayType, typename basic_json_t::reverse_iterator >::value and not std::is_same< CompatibleArrayType, typename basic_json_t::const_reverse_iterator >::value and not std::is_same< CompatibleArrayType, typename array_t::iterator >::value and not std::is_same< CompatibleArrayType, typename array_t::const_iterator >::value and std::is_constructible< basic_json, typename CompatibleArrayType::value_type >::value, int >::type = 0>

nlohmann::basic_json::basic_json | ( | const CompatibleArrayType & | val | ) |

inline

Create an array JSON value with a given content. This constructor allows any type that can be used to construct values of type array_t. Examples include the types `std::vector`, `std::list`, and `std::set`.

Template Parameters

  CompatibleArrayType | an object type whose `value_type` is compatible to array_t

Parameters

  [in] | val | a value for the array

Complexity
  Linear in the size of the passed val.

Exceptions

  std::bad_alloc | if allocation for array value fails

Example
  The following code shows the constructor with several compatible array type parameters.
  #include <json.hpp>
  #include <deque>
  #include <list>
  #include <forward_list>
  #include <set>
  #include <unordered_set>
  using namespace nlohmann;
  int main()
  {
  // create an array from std::vector
  std::vector<int> c_vector {1, 2, 3, 4};
  json j_vec(c_vector);
  // create an array from std::deque
  std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6};
  json j_deque(c_deque);
  // create an array from std::list
  std::list<bool> c_list {true, true, false, true};
  json j_list(c_list);
  // create an array from std::forward_list
  std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543};
  json j_flist(c_flist);
  // create an array from std::array
  std::array<unsigned long, 4> c_array {{1, 2, 3, 4}};
  json j_array(c_array);
  // create an array from std::set
  std::set<std::string> c_set {"one", "two", "three", "four", "one"};
  json j_set(c_set); // only one entry for "one" is used
  // create an array from std::unordered_set
  std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"};
  json j_uset(c_uset); // only one entry for "one" is used
  // create an array from std::multiset
  std::multiset<std::string> c_mset {"one", "two", "one", "four"};
  json j_mset(c_mset); // only one entry for "one" is used
  // create an array from std::unordered_multiset
  std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};
  json j_umset(c_umset); // both entries for "one" are used
  // serialize the JSON arrays
  std::cout << j_vec << '\n';
  std::cout << j_deque << '\n';
  std::cout << j_list << '\n';
  std::cout << j_flist << '\n';
  std::cout << j_array << '\n';
  std::cout << j_set << '\n';
  std::cout << j_uset << '\n';
  std::cout << j_mset << '\n';
  std::cout << j_umset << '\n';
  }
  nlohmann::basic_json
  a class to store JSON values
  Definition: json.hpp:191
  nlohmann
  namespace for Niels Lohmann
  Definition: json.hpp:88
  Output (play with this example online):

      [1,2,3,4]
      [1.2,2.3,3.4,5.6]
      [true,true,false,true]
      [12345678909876,23456789098765,34567890987654,45678909876543]
      [1,2,3,4]
      ["four","one","three","two"]
      ["four","three","two","one"]
      ["four","one","one","two"]
      ["four","two","one","one"]

  The example code above can be translated with

      g++ -std=c++11 -Isrc doc/examples/basic_json__CompatibleArrayType.cpp -o basic_json__CompatibleArrayType

See also
  basic_json(const array_t&) – create an array value

Since
  version 1.0.0

Definition at line 1039 of file json.hpp.