• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# basic_json::object
2
3```cpp
4static basic_json object(initializer_list_t init = {});
5```
6
7Creates a JSON object value from a given initializer list. The initializer lists elements must be pairs, and their first
8elements must be strings. If the initializer list is empty, the empty object `#!json {}` is created.
9
10## Parameters
11
12`init` (in)
13:   initializer list with JSON values to create an object from (optional)
14
15## Return value
16
17JSON object value
18
19## Exceptions
20
21Throws [`type_error.301`](../../home/exceptions.md#jsonexceptiontype_error301) if `init` is not a list of pairs whose
22first elements are strings. In this case, no object can be created. When such a value is passed to
23`basic_json(initializer_list_t, bool, value_t)`, an array would have been created from the passed initializer list
24`init`. See example below.
25
26## Exception safety
27
28Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
29
30## Complexity
31
32Linear in the size of `init`.
33
34## Notes
35
36This function is only added for symmetry reasons. In contrast to the related function `array(initializer_list_t)`, there
37are no cases which can only be expressed by this function. That is, any initializer list `init` can also be passed to
38the initializer list constructor `basic_json(initializer_list_t, bool, value_t)`.
39
40## Examples
41
42??? example
43
44    The following code shows an example for the `object` function.
45
46    ```cpp
47    --8<-- "examples/object.cpp"
48    ```
49
50    Output:
51
52    ```json
53    --8<-- "examples/object.output"
54    ```
55
56## Version history
57
58- Added in version 1.0.0.
59