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::arrayis a static function that converts an initializer list into ajsonvalue with internal typevalue_t::array.array_tis defined as follows:where
ArrayTypeis a template template parameter tobasic_json:and finally
nlohmann::jsonis just the default instantiation:So,
json::array_tis in the end a type alias forstd::vector<json>.You can override the types passed to
basic_jsonif you create your own typedef overbasic_json.