2017-07-09 11:51:38 +02:00
|
|
|
#include <iostream>
|
2017-04-14 17:36:45 +02:00
|
|
|
#include <iomanip> // for std::setw
|
2017-07-09 11:51:38 +02:00
|
|
|
#include "json.hpp"
|
2015-06-29 23:02:41 +02:00
|
|
|
|
2016-01-30 20:23:14 +01:00
|
|
|
using json = nlohmann::json;
|
2015-06-29 23:02:41 +02:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// create a JSON object
|
2015-06-30 00:12:18 +02:00
|
|
|
json j =
|
|
|
|
{
|
2015-06-29 23:02:41 +02:00
|
|
|
{"pi", 3.141},
|
|
|
|
{"happy", true},
|
|
|
|
{"name", "Niels"},
|
|
|
|
{"nothing", nullptr},
|
2015-06-30 00:12:18 +02:00
|
|
|
{
|
|
|
|
"answer", {
|
|
|
|
{"everything", 42}
|
|
|
|
}
|
|
|
|
},
|
2015-06-29 23:02:41 +02:00
|
|
|
{"list", {1, 0, 2}},
|
2015-06-30 00:12:18 +02:00
|
|
|
{
|
|
|
|
"object", {
|
|
|
|
{"currency", "USD"},
|
|
|
|
{"value", 42.99}
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 23:02:41 +02:00
|
|
|
};
|
2015-06-30 00:12:18 +02:00
|
|
|
|
2015-06-29 23:02:41 +02:00
|
|
|
// add new values
|
|
|
|
j["new"]["key"]["value"] = {"another", "list"};
|
|
|
|
|
|
|
|
// count elements
|
2017-04-14 17:36:45 +02:00
|
|
|
auto s = j.size();
|
|
|
|
j["size"] = s;
|
2015-06-30 00:12:18 +02:00
|
|
|
|
2015-06-29 23:02:41 +02:00
|
|
|
// pretty print with indent of 4 spaces
|
|
|
|
std::cout << std::setw(4) << j << '\n';
|
|
|
|
}
|