Lines Matching full:json

2 //  __|  |   __|     |   | |  JSON for Modern C++ (supporting code)
4 // |_____|_____|_____|_|___| https://github.com/nlohmann/json
11 #include <nlohmann/json.hpp>
12 using nlohmann::json;
16 json j_array = {13, 29, 3, {{"one", 1}, {"two", 2}}, true, false, {1, 2, 3}, "foo", "baz"};
17 json j_object = {{"one", 1}, {"two", 2}};
23 CHECK(std::all_of(j_array.begin(), j_array.end(), [](const json & value)
27 CHECK(std::all_of(j_object.begin(), j_object.end(), [](const json & value)
29 return value.type() == json::value_t::number_integer;
35 CHECK(std::any_of(j_array.begin(), j_array.end(), [](const json & value)
39 CHECK(std::any_of(j_object.begin(), j_object.end(), [](const json & value)
47 CHECK(std::none_of(j_array.begin(), j_array.end(), [](const json & value)
51 CHECK(std::none_of(j_object.begin(), j_object.end(), [](const json & value)
63 std::for_each(j_array.cbegin(), j_array.cend(), [&sum](const json & value)
76 auto add17 = [](json & value)
86 CHECK(j_array[6] == json({1, 2, 3, 17}));
92 CHECK(std::count(j_array.begin(), j_array.end(), json(true)) == 1);
97 CHECK(std::count_if(j_array.begin(), j_array.end(), [](const json & value)
101 CHECK(std::count_if(j_array.begin(), j_array.end(), [](const json&)
109 json j_array2 = {13, 29, 3, {{"one", 1}, {"two", 2}, {"three", 3}}, true, false, {1, 2, 3}, "foo", "baz"};
111 CHECK(*res.first == json({{"one", 1}, {"two", 2}}));
112 CHECK(*res.second == json({{"one", 1}, {"two", 2}, {"three", 3}}));
127 json j_array2 = {13, 29, 3, {"Hello", "World"}, true, false, {{"one", 1}, {"two", 2}, {"three", 3}}, "foo", "baz"};
130 [](const json & a, const json & b)
139 auto it = std::find(j_array.begin(), j_array.end(), json(false));
146 [](const json & value)
156 [](const json & value)
167 [](const json & v1, const json & v2)
179 CHECK(j_array == json({"baz", "foo", {1, 2, 3}, false, true, {{"one", 1}, {"two", 2}}, 3, 29, 13}));
185 CHECK(j_array == json({29, 3, {{"one", 1}, {"two", 2}}, true, false, {1, 2, 3}, "foo", "baz", 13}));
190 auto it = std::partition(j_array.begin(), j_array.end(), [](const json & v)
205 json j = {13, 29, 3, {{"one", 1}, {"two", 2}}, true, false, {1, 2, 3}, "foo", "baz", nullptr};
207 CHECK(j == json({nullptr, false, true, 3, 13, 29, {{"one", 1}, {"two", 2}}, {1, 2, 3}, "baz", "foo"}));
212 json j = {3, {{"one", 1}, {"two", 2}}, {1, 2, 3}, nullptr};
213 std::sort(j.begin(), j.end(), [](const json & a, const json & b)
217 CHECK(j == json({nullptr, 3, {{"one", 1}, {"two", 2}}, {1, 2, 3}}));
222 json j({{"one", 1}, {"two", 2}});
223 CHECK_THROWS_WITH_AS(std::sort(j.begin(), j.end()), "[json.exception.invalid_iterator.209] cannot use offsets with object iterators", json::invalid_iterator&);
229 json j = {13, 29, 3, {{"one", 1}, {"two", 2}}, true, false, {1, 2, 3}, "foo", "baz", nullptr};
231 CHECK(j == json({nullptr, false, true, 3, {{"one", 1}, {"two", 2}}, 29, {1, 2, 3}, "foo", "baz", 13}));
240 json j1 = {2, 4, 6, 8};
241 json j2 = {1, 2, 3, 5, 7};
242 json j3;
245 CHECK(j3 == json({1, 2, 2, 3, 4, 5, 6, 7, 8}));
251 json j1 = {1, 2, 3, 4, 5, 6, 7, 8};
252 json j2 = {1, 2, 3, 5, 7};
253 json j3;
256 CHECK(j3 == json({4, 6, 8}));
261 json j1 = {1, 2, 3, 4, 5, 6, 7, 8};
262 json j2 = {1, 2, 3, 5, 7};
263 json j3;
266 CHECK(j3 == json({1, 2, 3, 5, 7}));
271 json j1 = {2, 4, 6, 8};
272 json j2 = {1, 2, 3, 5, 7};
273 json j3;
276 CHECK(j3 == json({1, 2, 3, 4, 5, 6, 7, 8}));
281 json j1 = {2, 4, 6, 8};
282 json j2 = {1, 2, 3, 5, 7};
283 json j3;
286 CHECK(j3 == json({1, 3, 4, 5, 6, 7, 8}));
295 CHECK(j_array == json({false, true, 3, 13, 29, {{"one", 1}, {"two", 2}}, {1, 2, 3}, "baz", "foo"}));