template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator></div>
<p>Creates a JSON value of type array or object from the passed initializer list <em>init</em>. In case <em>type_deduction</em> is <code>true</code> (default), the type of the JSON value to be created is deducted from the initializer list <em>init</em> according to the following rules:</p>
<oltype="1">
<li>If the list is empty, an empty JSON object value <code>{}</code> is created.</li>
<li>If the list consists of pairs whose first element is a string, a JSON object value is created where the first elements of the pairs are treated as keys and the second elements are as values.</li>
<li>In all other cases, an array is created.</li>
</ol>
<p>The rules aim to create the best fit between a C++ initializer list and JSON values. The ratioinale is as follows:</p>
<oltype="1">
<li>The empty initializer list is written as <code>{}</code> which is exactly an empty JSON object.</li>
<li>C++ has now way of describing mapped types other than to list a list of pairs. As JSON requires that keys must be of type string, rule 2 is the weakest constraint one can pose on initializer lists to interpret them as an object.</li>
<li>In all other cases, the initializer list could not be interpreted as JSON object type, so interpreting it as JSON array type is safe.</li>
</ol>
<p>With the rules described above, the following JSON values cannot be expressed by an initializer list:</p>
<ul>
<li>the empty array (<code>[]</code>): use <aclass="el"href="classnlohmann_1_1basic__json_a53590b99e380c464a83a0a5edf6da9ab.html#a53590b99e380c464a83a0a5edf6da9ab">array(list_init_t)</a> with an empty initializer list in this case</li>
<li>arrays whose elements satisfy rule 2: use <aclass="el"href="classnlohmann_1_1basic__json_a53590b99e380c464a83a0a5edf6da9ab.html#a53590b99e380c464a83a0a5edf6da9ab">array(list_init_t)</a> with the same initializer list in this case</li>
</ul>
<dlclass="section note"><dt>Note</dt><dd>When used without parentheses around an empty initializer list, <aclass="el"href="classnlohmann_1_1basic__json_a5a2d4dbcdbc8ea065b87daf52cd786b9.html#a5a2d4dbcdbc8ea065b87daf52cd786b9">basic_json()</a> is called instead of this function, yielding the JSON null value.</dd></dl>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">init</td><td>initializer list with JSON values</td></tr>
<tr><tdclass="paramname">type_deduction</td><td>internal parameter; when set to <code>true</code>, the type of the JSON value is deducted from the initializer list <em>init</em>; when set to <code>false</code>, the type provided via <em>manual_type</em> is forced. This mode is used by the functions <aclass="el"href="classnlohmann_1_1basic__json_a53590b99e380c464a83a0a5edf6da9ab.html#a53590b99e380c464a83a0a5edf6da9ab">array(list_init_t)</a> and <aclass="el"href="classnlohmann_1_1basic__json_afb9664e6f30038e691f2e864e7f6a740.html#afb9664e6f30038e691f2e864e7f6a740">object(list_init_t)</a>.</td></tr>
<tr><tdclass="paramname">manual_type</td><td>internal parameter; when <em>type_deduction</em> is set to <code>false</code>, the created JSON value will use the provided type (only <aclass="el"href="classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html#a231b02148577b69a154b2ce2c87a5522af1f713c9e000f5d3f280adbd124df4f5">value_t::array</a> and <aclass="el"href="classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html#a231b02148577b69a154b2ce2c87a5522aa8cfde6331bd59eb2ac96f8911c4b666">value_t::object</a> are valid); when <em>type_deduction</em> is set to <code>true</code>, this parameter has no effect</td></tr>
</table>
</dd>
</dl>
<dlclass="exception"><dt>Exceptions</dt><dd>
<tableclass="exception">
<tr><tdclass="paramname">std::domain_error</td><td>if <em>type_deduction</em> is <code>false</code>, <em>manual_type</em> is <code><aclass="el"href="classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html#a231b02148577b69a154b2ce2c87a5522aa8cfde6331bd59eb2ac96f8911c4b666"title="object (unordered set of name/value pairs) ">value_t::object</a></code>, but <em>init</em> contains an element which is not a pair whose first element is a string</td></tr>
</table>
</dd>
</dl>
<dlclass="section user"><dt>Complexity</dt><dd>Linear in the size of the initializer list <em>init</em>.</dd></dl>
<dlclass="section user"><dt>Example</dt><dd>The example below shows how JSON values are created from initializer lists <divclass="fragment"><divclass="line"><aname="l00001"></a><spanclass="lineno"> 1</span> <spanclass="preprocessor">#include <json.hpp></span></div>
<divclass="ttc"id="namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474_html_a2bfd99e845a2e5cd90aeaf1b1431f474"><divclass="ttname"><ahref="namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html#a2bfd99e845a2e5cd90aeaf1b1431f474">nlohmann::json</a></div><divclass="ttdeci">basic_json<> json</div><divclass="ttdoc">default JSON class </div><divclass="ttdef"><b>Definition:</b> json.hpp:5634</div></div>
<divclass="ttc"id="classnlohmann_1_1basic__json_html"><divclass="ttname"><ahref="classnlohmann_1_1basic__json.html">nlohmann::basic_json</a></div><divclass="ttdoc">a class to store JSON values </div><divclass="ttdef"><b>Definition:</b> json.hpp:113</div></div>
<divclass="ttc"id="namespacenlohmann_html"><divclass="ttname"><ahref="namespacenlohmann.html">nlohmann</a></div><divclass="ttdoc">namespace for Niels Lohmann </div><divclass="ttdef"><b>Definition:</b> json.hpp:49</div></div>
</div><!-- fragment --> Output: <preclass="fragment">{}
{"one":1,"two":2}
[1,2,3,4]
{"one":[1],"two":[1,2]}
[[[1],"one"],[[1,2],"two"]]
</pre> The example code above can be translated with<preclass="fragment">g++ -std=c++11 -Isrc doc/examples/basic_json__list_init_t.cpp -o basic_json__list_init_t </pre>.</dd></dl>
<dlclass="section see"><dt>See also</dt><dd><aclass="el"href="classnlohmann_1_1basic__json.html"title="a class to store JSON values ">basic_json</a><aclass="el"href="classnlohmann_1_1basic__json_a53590b99e380c464a83a0a5edf6da9ab.html#a53590b99e380c464a83a0a5edf6da9ab"title="explicitly create an array from an initializer list ">array(list_init_t)</a> - create a JSON <aclass="el"href="classnlohmann_1_1basic__json_a53590b99e380c464a83a0a5edf6da9ab.html#a53590b99e380c464a83a0a5edf6da9ab"title="explicitly create an array from an initializer list ">array</a> value from an initializer list </dd>
<dd>
<aclass="el"href="classnlohmann_1_1basic__json.html"title="a class to store JSON values ">basic_json</a><aclass="el"href="classnlohmann_1_1basic__json_afb9664e6f30038e691f2e864e7f6a740.html#afb9664e6f30038e691f2e864e7f6a740"title="explicitly create an object from an initializer list ">object(list_init_t)</a> - create a JSON <aclass="el"href="classnlohmann_1_1basic__json_afb9664e6f30038e691f2e864e7f6a740.html#afb9664e6f30038e691f2e864e7f6a740"title="explicitly create an object from an initializer list ">object</a> value from an initializer list </dd></dl>
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<divid="nav-path"class="navpath"><!-- id is needed for treeview function! -->