basic_json::type

constexpr value_t type() const noexcept;

Return the type of the JSON value as a value from the value_t enumeration.

Return value

the type of the JSON value

Value typereturn value
#!json nullvalue_t::null
booleanvalue_t::boolean
stringvalue_t::string
number (integer)value_t::number_integer
number (unsigned integer)value_t::number_unsigned
number (floating-point)value_t::number_float
objectvalue_t::object
arrayvalue_t::array
binaryvalue_t::binary
discardedvalue_t::discarded

Exception safety

No-throw guarantee: this member function never throws exceptions.

Complexity

Constant.

Example

??? example

The following code exemplifies `type()` for all JSON types.

```cpp
--8<-- "examples/type.cpp"
```

Output:

```json
--8<-- "examples/type.output"
```

Version history

  • Added in version 1.0.0.
  • Added unsigned integer type in version 2.0.0.
  • Added binary type in version 3.8.0.