You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

753 B

#include <iostream>
#include <iomanip>
#include <nlohmann json.hpp="">

using json = nlohmann::json;

int main()
{
// create a JSON object
json j =
{
{&#34;pi&#34;, 3.141},
{&#34;happy&#34;, true},
{&#34;name&#34;, &#34;Niels&#34;},
{&#34;nothing&#34;, nullptr},
{
&#34;answer&#34;, {
{&#34;everything&#34;, 42}
}
},
{&#34;list&#34;, {1, 0, 2}},
{
&#34;object&#34;, {
{&#34;currency&#34;, &#34;USD&#34;},
{&#34;value&#34;, 42.99}
}
}
};

// add new values
j[&#34;new&#34;][&#34;key&#34;][&#34;value&#34;] = {&#34;another&#34;, &#34;list&#34;};

// count elements
auto s = j.size();
j[&#34;size&#34;] = s;

// pretty print with indent of 4 spaces
std::cout &lt;&lt; std::setw(4) &lt;&lt; j &lt;&lt; &#39;\n&#39;;
}