basic_json::operator ValueType

template<typename ValueType>
JSON_EXPLICIT operator ValueType() const;

Implicit type conversion between the JSON value and a compatible value. The call is realized by calling get(). See Notes for the meaning of JSON_EXPLICIT.

Template parameters

ValueType : the value type to return

Return value

copy of the JSON value, converted to ValueType

Exceptions

Depends on what json_serializer<ValueType> from_json() method throws

Complexity

Linear in the size of the JSON value.

Notes

By default JSON_EXPLICIT defined to the empty string, so the signature is:

template<typename ValueType>
operator ValueType() const;

If JSON_USE_IMPLICIT_CONVERSIONS is set to 0, JSON_EXPLICIT is defined to #!cpp explicit:

template<typename ValueType>
explicit operator ValueType() const;

That is, implicit conversions can be switched off by defining JSON_USE_IMPLICIT_CONVERSIONS to 0.

Example

??? example

The example below shows several conversions from JSON values
to other types. There a few things to note: (1) Floating-point numbers can
be converted to integers, (2) A JSON array can be converted to a standard
`std::vector<short>`, (3) A JSON object can be converted to C++
associative containers such as `std::unordered_map<std::string, json>`.
    
```cpp
--8<-- "examples/operator__ValueType.cpp"
```

Output:

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

Version history