| # <small>nlohmann::basic_json::</small>array_t | |
| ```cpp | |
| using array_t = ArrayType<basic_json, AllocatorType<basic_json>>; | |
| ``` | |
| The type used to store JSON arrays. | |
| [RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON arrays as follows: | |
| > An array is an ordered sequence of zero or more values. | |
| To store objects in C++, a type is defined by the template parameters explained below. | |
| ## Template parameters | |
| `ArrayType` | |
| : container type to store arrays. It must be a vector-like container: the library uses `operator[]`, `at()`, and | |
| `resize()`, and requires random-access iterators. `#!cpp std::vector` and `#!cpp std::deque` qualify; | |
| `#!cpp std::list` does not. See | |
| [Template Parameter Requirements](../../features/types/template_parameters.md#arraytype) for the full list of | |
| requirements. | |
| `AllocatorType` | |
| : the allocator to use for objects (e.g., `std::allocator`) | |
| ## Notes | |
| ### Default type | |
| With the default values for `ArrayType` (`std::vector`) and `AllocatorType` (`std::allocator`), the default type for | |
| `array_t` is: | |
| ```cpp | |
| std::vector< | |
| basic_json, // value_type | |
| std::allocator<basic_json> // allocator_type | |
| > | |
| ``` | |
| ### Limits | |
| [RFC 8259](https://tools.ietf.org/html/rfc8259) specifies: | |
| > An implementation may set limits on the maximum depth of nesting. | |
| In this class, the array's limit of nesting is not explicitly constrained. However, a maximum depth of nesting may be | |
| introduced by the compiler or runtime environment. A theoretical limit can be queried by calling the | |
| [`max_size`](max_size.md) function of a JSON array. | |
| ### Storage | |
| Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of type | |
| `#!cpp array_t*` must be dereferenced. | |
| ## Examples | |
| ??? example | |
| The following code shows that `array_t` is by default, a typedef to `#!cpp std::vector<nlohmann::json>`. | |
| ```cpp | |
| #include <iostream> | |
| #include <iomanip> | |
| #include <nlohmann/json.hpp> | |
| using json = nlohmann::json; | |
| int main() | |
| { | |
| std::cout << std::boolalpha << std::is_same<std::vector<json>, json::array_t>::value << std::endl; | |
| } | |
| ``` | |
| Output: | |
| ```json | |
| true | |
| ``` | |
| ## See also | |
| - [object_t](object_t.md) the type used to store JSON objects | |
| - [binary_t](binary_t.md) the type used to store binary values | |
| - [is_array](is_array.md) checks whether the JSON value is an array | |
| - [max_size](max_size.md) returns the maximum possible number of elements | |
| ## Version history | |
| - Added in version 1.0.0. | |
| - Made `capacity()` optional, so that array types such as `#!cpp std::deque` can be used, in version 3.13.0. |