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 array value from a given initializer list. That is, given a list of values <code>a, b, c</code>, creates the JSON value <code>[a, b, c]</code>. If the initializer list is empty, the empty array <code>[]</code> is created.</p>
<dlclass="section note"><dt>Note</dt><dd>This function is only needed to express two edge cases that cannot be realized with the initializer list constructor (<aclass="el"href="classnlohmann_1_1basic__json_a444d8376d63d7a5edb85f33bc5976c14.html#a444d8376d63d7a5edb85f33bc5976c14">basic_json(list_init_t, bool, value_t)</a>). These cases are:<oltype="1">
<li>creating an array whose elements are all pairs whose first element is a string - in this case, the initializer list constructor would create an object, taking the first elements as keys</li>
<li>creating an empty array - passing the empty initializer list to the initializer list constructor yields an empty object</li>
<dlclass="section user"><dt>Complexity</dt><dd>Linear in the size of <em>init</em>.</dd></dl>
<dlclass="section user"><dt>Example</dt><dd>The following code shows an example for the <aclass="el"href="classnlohmann_1_1basic__json_a53590b99e380c464a83a0a5edf6da9ab.html#a53590b99e380c464a83a0a5edf6da9ab">array</a> function. <divclass="fragment"><divclass="line"><aname="l00001"></a><spanclass="lineno"> 1</span> <spanclass="preprocessor">#include <json.hpp></span></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:121</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:56</div></div>
<divclass="ttc"id="classnlohmann_1_1basic__json_a53590b99e380c464a83a0a5edf6da9ab_html_a53590b99e380c464a83a0a5edf6da9ab"><divclass="ttname"><ahref="classnlohmann_1_1basic__json_a53590b99e380c464a83a0a5edf6da9ab.html#a53590b99e380c464a83a0a5edf6da9ab">nlohmann::basic_json::array</a></div><divclass="ttdeci">static basic_json array(list_init_t init=list_init_t())</div><divclass="ttdoc">explicitly create an array from an initializer list </div><divclass="ttdef"><b>Definition:</b> json.hpp:970</div></div>
</div><!-- fragment --> Output: <preclass="fragment">[]
[]
[1,2,3,4]
[["one",1],["two",2]]
</pre> The example code above can be translated with<preclass="fragment">g++ -std=c++11 -Isrc doc/examples/array.cpp -o array </pre>.</dd></dl>
<dlclass="section see"><dt>See also</dt><dd><aclass="el"href="classnlohmann_1_1basic__json_a444d8376d63d7a5edb85f33bc5976c14.html#a444d8376d63d7a5edb85f33bc5976c14"title="create a container (array or object) from an initializer list ">basic_json(list_init_t, bool, value_t)</a> - create a JSON 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! -->