How is nlohmann array_t different from Nlohmann json array? How is array_t actually used? The documentation for each is as follows.
Creates a JSON array value from a given initializer list. That is, given a list of values a, b, c, creates the JSON value [a, b, c]. If the initializer list is empty, the empty array [] is created.
Example,
nlohmann::json j_nonempty_init_list = json::array({1, 2, 3, 4});
std::cout << j_nonempty_init_list;
// [1,2,3,4]
To store objects in C++, a type is defined by the template parameters explained below.
- Template Parameters
- ArrayType container type to store arrays (e.g., std::vector or std::list)
- AllocatorType allocator to use for arrays (e.g., std::allocator)
json::array
is a static function that converts an initializer list into ajson
value with internal typevalue_t::array
.array_t
is defined as follows:where
ArrayType
is a template template parameter tobasic_json
:and finally
nlohmann::json
is just the default instantiation:So,
json::array_t
is in the end a type alias forstd::vector<json>
.You can override the types passed to
basic_json
if you create your own typedef overbasic_json
.