Lines Matching full:json

2 //  __|  |   __|     |   | |  JSON for Modern C++ (supporting code)
4 // |_____|_____|_____|_|___| https://github.com/nlohmann/json
18 #include <nlohmann/json.hpp>
19 using nlohmann::json;
23 SECTION("empty JSON Pointer")
25 json j = 1;
27 CHECK_THROWS_WITH_AS(s = j.get<std::string>(), "[json.exception.type_error.302] type must be string, but is number", json::type_error);
32 json j;
35 CHECK_THROWS_WITH_AS(s = j["a"]["b"]["c"].get<std::string>(), "[json.exception.type_error.302] (/a/b/c) type must be string, but is number", json::type_error);
40 json j;
42 CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key 'not_found' not found", json::out_of_range);
47 json j;
49 CHECK_THROWS_WITH_AS(j["array"].at(5), "[json.exception.out_of_range.401] (/array) array index 5 is out of range", json::out_of_range);
54 json j;
56 CHECK_THROWS_WITH_AS(j["array"][4][5], "[json.exception.type_error.305] (/array/4) cannot use operator[] with a numeric argument with boolean", json::type_error);
61 json j;
62 j["array"] = json::array();
63 CHECK_THROWS_WITH_AS(j["array"].erase(j.begin()), "[json.exception.invalid_iterator.202] (/array) iterator does not fit current value", json::invalid_iterator);
66 SECTION("JSON Pointer escaping")
68 json j;
71 CHECK_THROWS_WITH_AS(s = j["a/b"]["m~n"].get<std::string>(), "[json.exception.type_error.302] (/a~1b/m~0n) type must be string, but is number", json::type_error);
76 json _;
77 CHECK_THROWS_WITH_AS(_ = json::parse(""), "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error);
82 json j = {{"foo", "bar"}};
83 json k = {{"bla", 1}};
85 CHECK_THROWS_WITH_AS(j.update(k["bla"].begin(), k["bla"].end()), "[json.exception.type_error.312] (/bla) cannot use update() with number", json::type_error);
86 CHECK_THROWS_WITH_AS(j.update(k["bla"]), "[json.exception.type_error.312] (/bla) cannot use update() with number", json::type_error);
92 SECTION("Regression test for https://github.com/nlohmann/json/pull/2562#pullrequestreview-574858448")
94 CHECK_THROWS_WITH_AS(json({"0", "0"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
95 CHECK_THROWS_WITH_AS(json({"0", "1"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
98 SECTION("Regression test for https://github.com/nlohmann/json/pull/2562/files/380a613f2b5d32425021129cd1f371ddcfd54ddf#r563259793")
100 json j;
102 CHECK_THROWS_WITH_AS(j.unflatten(), "[json.exception.type_error.315] (/~1foo) values in object must be primitive", json::type_error);
109 json j_arr = json::array();
110 j_arr.push_back(json::object());
111 j_arr.push_back(json::object());
112 j_arr.push_back(json::object());
113 j_arr.push_back(json::object());
114 json j_obj = json::object();
120 json j_arr = json::array();
121 auto object = json::object();
126 json j_obj = json::object();
132 json j_arr = json::array();
133 j_arr.emplace_back(json::object());
134 j_arr.emplace_back(json::object());
135 j_arr.emplace_back(json::object());
136 j_arr.emplace_back(json::object());
137 json j_obj = json::object();
143 json j_arr = json::array();
144 j_arr.insert(j_arr.begin(), json::object());
145 j_arr.insert(j_arr.begin(), json::object());
146 j_arr.insert(j_arr.begin(), json::object());
147 j_arr.insert(j_arr.begin(), json::object());
148 json j_obj = json::object();
154 json j_arr = json::array();
155 j_arr.insert(j_arr.begin(), 2, json::object());
156 json j_obj = json::object();
162 json j_arr = json::array();
163 json j_objects = {json::object(), json::object()};
165 json j_obj = json::object();
184 json j = json::object();
187 json j2 = json::object();
195 CHECK_THROWS_WITH_AS(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number", json::type_error);
200 json j = json::object();
203 json j2 = json::object();
211 CHECK_THROWS_WITH_AS(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number", json::type_error);
216 json root = json::array();
217 json lower = json::object();
220 json lowest = json::object();
234 json j_arr = json::array();
243 json j_arr_copy = j_arr;