]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | # <small>nlohmann::basic_json::</small>type_name |
2 | ||
3 | ```cpp | |
4 | const char* type_name() const noexcept; | |
5 | ``` | |
6 | ||
7 | Returns the type name as string to be used in error messages -- usually to indicate that a function was called on a | |
8 | wrong JSON type. | |
9 | ||
10 | ## Return value | |
11 | ||
12 | a string representation of the type ([`value_t`](value_t.md)): | |
13 | ||
14 | | Value type | return value | | |
15 | |----------------------------------------------------|---------------| | |
16 | | `#!json null` | `"null"` | | |
17 | | boolean | `"boolean"` | | |
18 | | string | `"string"` | | |
19 | | number (integer, unsigned integer, floating-point) | `"number"` | | |
20 | | object | `"object"` | | |
21 | | array | `"array"` | | |
22 | | binary | `"binary"` | | |
23 | | discarded | `"discarded"` | | |
24 | ||
25 | ## Exception safety | |
26 | ||
27 | No-throw guarantee: this member function never throws exceptions. | |
28 | ||
29 | ## Complexity | |
30 | ||
31 | Constant. | |
32 | ||
33 | ## Examples | |
34 | ||
35 | ??? example | |
36 | ||
37 | The following code exemplifies `type_name()` for all JSON types. | |
38 | ||
39 | ```cpp | |
40 | --8<-- "examples/type_name.cpp" | |
41 | ``` | |
42 | ||
43 | Output: | |
44 | ||
45 | ```json | |
46 | --8<-- "examples/type_name.output" | |
47 | ``` | |
48 | ||
49 | ## Version history | |
50 | ||
51 | - Added in version 1.0.0. | |
52 | - Part of the public API version since 2.1.0. | |
53 | - Changed return value to `const char*` and added `noexcept` in version 3.0.0. | |
54 | - Added support for binary type in version 3.8.0. |