The example shows how push_back()
and +=
can be used to add elements to a JSON array. Note how the null
value was silently converted to a JSON array.
2 #include <nlohmann/json.hpp>
13 std::cout <<
array <<
'\n';
14 std::cout <<
null <<
'\n';
23 std::cout <<
array <<
'\n';
24 std::cout <<
null <<
'\n';
Output (play with this example online): [1,2,3,4,5]
null
[1,2,3,4,5,6,7]
["first","second"]
The example code above can be translated withg++ -std=c++11 -Isingle_include doc/examples/push_back.cpp -o push_back