[#nlohmann-basic_json-0e-2conversion-03] = xref:nlohmann.adoc[nlohmann]::xref:nlohmann/basic_json-0e.adoc[basic_json<>]::operator ValueType :relfileprefix: ../../ :mrdocs: get a value (implicit) == Synopsis Declared in `<nlohmann/json.hpp>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<typename ValueType> requires detail::conjunction < detail::negation<std::is_pointer<ValueType>>, detail::negation<std::is_same<ValueType, std::nullptr_t>>, detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>, detail::negation<std::is_same<ValueType, typename string_t::value_type>>, detail::negation<detail::is_basic_json<ValueType>>, detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>, #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914)) detail::negation<std::is_same<ValueType, std::string_view>>, #endif #if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI detail::negation<std::is_same<ValueType, std::any>>, #endif detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType> >::value operator ValueType() const; ---- == Description Implicit type conversion between the JSON value and a compatible value. The call is realized by calling xref:nlohmann/basic_json-0e/get-01.adoc[`get() const`]. Linear in the size of the JSON value. {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>`.,operator_ValueType} == Exceptions [cols=2] |=== | Name | Thrown on | `type_error.302` | in case passed type _ValueType_ is incompatible to the JSON value type (e.g., the JSON value is of type boolean, but a string is requested); see example below |=== == Return Value copy of the JSON value, converted to type _ValueType_ == Template Parameters [cols=2] |=== | Name | Description | *ValueType* | non‐pointer type compatible to the JSON value, for instance `int` for JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for JSON arrays. The character type of xref:nlohmann/basic_json-0e/string_t.adoc[`string_t`] as well as an initializer list of this type is excluded to avoid ambiguities as these types implicitly convert to `std::string`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#