]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | # <small>nlohmann::basic_json::</small>array_t |
2 | ||
3 | ```cpp | |
4 | using array_t = ArrayType<basic_json, AllocatorType<basic_json>>; | |
5 | ``` | |
6 | ||
7 | The type used to store JSON arrays. | |
8 | ||
9 | [RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON arrays as follows: | |
10 | > An array is an ordered sequence of zero or more values. | |
11 | ||
12 | To store objects in C++, a type is defined by the template parameters explained below. | |
13 | ||
14 | ## Template parameters | |
15 | ||
16 | `ArrayType` | |
17 | : container type to store arrays (e.g., `std::vector` or `std::list`) | |
18 | ||
19 | `AllocatorType` | |
20 | : the allocator to use for objects (e.g., `std::allocator`) | |
21 | ||
22 | ## Notes | |
23 | ||
24 | #### Default type | |
25 | ||
26 | With the default values for `ArrayType` (`std::vector`) and `AllocatorType` (`std::allocator`), the default value for | |
27 | `array_t` is: | |
28 | ||
29 | ```cpp | |
30 | std::vector< | |
31 | basic_json, // value_type | |
32 | std::allocator<basic_json> // allocator_type | |
33 | > | |
34 | ``` | |
35 | ||
36 | #### Limits | |
37 | ||
38 | [RFC 8259](https://tools.ietf.org/html/rfc8259) specifies: | |
39 | > An implementation may set limits on the maximum depth of nesting. | |
40 | ||
41 | In this class, the array's limit of nesting is not explicitly constrained. However, a maximum depth of nesting may be | |
42 | introduced by the compiler or runtime environment. A theoretical limit can be queried by calling the | |
43 | [`max_size`](max_size.md) function of a JSON array. | |
44 | ||
45 | #### Storage | |
46 | ||
47 | Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of type | |
48 | `#!cpp array_t*` must be dereferenced. | |
49 | ||
50 | ## Examples | |
51 | ||
52 | ??? example | |
53 | ||
54 | The following code shows that `array_t` is by default, a typedef to `#!cpp std::vector<nlohmann::json>`. | |
55 | ||
56 | ```cpp | |
57 | --8<-- "examples/array_t.cpp" | |
58 | ``` | |
59 | ||
60 | Output: | |
61 | ||
62 | ```json | |
63 | --8<-- "examples/array_t.output" | |
64 | ``` | |
65 | ||
66 | ## Version history | |
67 | ||
68 | - Added in version 1.0.0. |