[#nlohmann-basic_json-00-2conversion-06]
= xref:nlohmann.adoc[nlohmann]::xref:nlohmann/basic_json-00.adoc[basic&lowbar;json]::operator ValueType
:relfileprefix: ../../
:mrdocs:

get a value (implicit)

== Synopsis

Declared in `&lt;nlohmann&sol;json&period;hpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;typename ValueType&gt;
requires detail&colon;&colon;conjunction &lt;
                       detail&colon;&colon;negation&lt;std&colon;&colon;is&lowbar;pointer&lt;ValueType&gt;&gt;,
                       detail&colon;&colon;negation&lt;std&colon;&colon;is&lowbar;same&lt;ValueType, std&colon;&colon;nullptr&lowbar;t&gt;&gt;,
                       detail&colon;&colon;negation&lt;std&colon;&colon;is&lowbar;same&lt;ValueType, detail&colon;&colon;json&lowbar;ref&lt;basic&lowbar;json&gt;&gt;&gt;,
                                        detail&colon;&colon;negation&lt;std&colon;&colon;is&lowbar;same&lt;ValueType, typename string&lowbar;t&colon;&colon;value&lowbar;type&gt;&gt;,
                                        detail&colon;&colon;negation&lt;detail&colon;&colon;is&lowbar;basic&lowbar;json&lt;ValueType&gt;&gt;,
                                        detail&colon;&colon;negation&lt;std&colon;&colon;is&lowbar;same&lt;ValueType, std&colon;&colon;initializer&lowbar;list&lt;typename string&lowbar;t&colon;&colon;value&lowbar;type&gt;&gt;&gt;,
&num;if defined(JSON&lowbar;HAS&lowbar;CPP&lowbar;17) &amp;&amp; (defined(&lowbar;&lowbar;GNUC&lowbar;&lowbar;) &verbar;&verbar; (defined(&lowbar;MSC&lowbar;VER) &amp;&amp; &lowbar;MSC&lowbar;VER &gt;&equals; 1910 &amp;&amp; &lowbar;MSC&lowbar;VER &lt;&equals; 1914))
                                                detail&colon;&colon;negation&lt;std&colon;&colon;is&lowbar;same&lt;ValueType, std&colon;&colon;string&lowbar;view&gt;&gt;,
&num;endif
&num;if defined(JSON&lowbar;HAS&lowbar;CPP&lowbar;17) &amp;&amp; JSON&lowbar;HAS&lowbar;STATIC&lowbar;RTTI
                                                detail&colon;&colon;negation&lt;std&colon;&colon;is&lowbar;same&lt;ValueType, std&colon;&colon;any&gt;&gt;,
&num;endif
&num;if defined(JSON&lowbar;HAS&lowbar;CPP&lowbar;17)
                                                &sol;&sol; std&colon;&colon;optional&lt;T&gt; can construct itself from basic&lowbar;json&semi; excluding it
                                                &sol;&sol; here avoids an ambiguity with that constructor (e&period;g&period;, under C&plus;&plus;26)
                                                detail&colon;&colon;negation&lt;detail&colon;&colon;is&lowbar;std&lowbar;optional&lt;ValueType&gt;&gt;,
&num;endif
                                                detail&colon;&colon;is&lowbar;detected&lowbar;lazy&lt;detail&colon;&colon;get&lowbar;template&lowbar;function, const basic&lowbar;json&lowbar;t&amp;, ValueType&gt;
                                                &gt;&colon;&colon;value
operator ValueType() const;
----

== Description

Implicit type conversion between the JSON value and a compatible value&period; The call is realized by calling xref:nlohmann/basic_json-00/get-0a.adoc[`get() const`]&period;

Linear in the size of the JSON value&period;

&lcub;The example below shows several conversions from JSON values to other types&period; There a few things to note&colon; (1) Floating&hyphen;point numbers can be converted to integers, (2) A JSON array can be converted to a standard `std&colon;&colon;vector&lt;short&gt;`, (3) A JSON object can be converted to C&plus;&plus; associative containers such as &grave;std&colon;&colon;unordered&lowbar;map&lt;std&colon;&colon;string&bsol;, json&gt;&grave;&period;,operator&lowbar;&lowbar;ValueType&rcub;

== Exceptions

[cols="1,4"]
|===
| Name| Thrown on
| `type&lowbar;error&period;302`
| in case passed type _ValueType_ is incompatible to the JSON value type (e&period;g&period;, the JSON value is of type boolean, but a string is requested)&semi; see example below
|===

== Return Value

copy of the JSON value, converted to type _ValueType_

== Template Parameters

[cols="1,4"]
|===
| Name| Description
| *ValueType*
| non&hyphen;pointer type compatible to the JSON value, for instance `int` for JSON integer numbers, `bool` for JSON booleans, or `std&colon;&colon;vector` types for JSON arrays&period; The character type of xref:nlohmann/basic_json-00/string_t.adoc[`string&lowbar;t`] as well as an initializer list of this type is excluded to avoid ambiguities as these types implicitly convert to `std&colon;&colon;string`&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
