• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# basic_json::emplace_back
2
3```cpp
4template<class... Args>
5reference emplace_back(Args&& ... args);
6```
7
8Creates a JSON value from the passed parameters `args` to the end of the JSON value. If the function is called on a JSON
9`#!json null` value, an empty array is created before appending the value created from `args`.
10
11## Template parameters
12
13`Args`
14:   compatible types to create a `basic_json` object
15
16## Parameters
17
18`args` (in)
19:   arguments to forward to a constructor of `basic_json`
20
21## Return value
22
23reference to the inserted element
24
25## Exceptions
26
27Throws [`type_error.311`](../../home/exceptions.md#jsonexceptiontype_error311) when called on a type other than JSON
28array or `#!json null`; example: `"cannot use emplace_back() with number"`
29
30## Complexity
31
32Amortized constant.
33
34## Examples
35
36??? example
37
38    The example shows how `emplace_back()` can be used to add elements to a JSON array. Note how the `null` value was
39    silently converted to a JSON array.
40
41    ```cpp
42    --8<-- "examples/emplace_back.cpp"
43    ```
44
45    Output:
46
47    ```json
48    --8<-- "examples/emplace_back.output"
49    ```
50
51## Version history
52
53- Since version 2.0.8.
54- Returns reference since 3.7.0.
55