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 // create a JSON value with different types
17 json json_types =
33 using test_type = json::object_t;
34 json value = {{"one", 1}, {"two", 2}};
46 CHECK_NOTHROW(value.get_ref<json::object_t&>());
47 CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
48 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
49 CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
50 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
51 CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
52 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
53 CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
54 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
55 CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
56 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
57 CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
58 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
63 using test_type = json::object_t;
64 const json value = {{"one", 1}, {"two", 2}};
77 using test_type = json::array_t;
78 json value = {1, 2, 3, 4};
90 CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
91 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
92 CHECK_NOTHROW(value.get_ref<json::array_t&>());
93 CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
94 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
95 CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
96 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
97 CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
98 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
99 CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
100 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
101 CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
102 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
107 using test_type = json::string_t;
108 json value = "hello";
120 CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
121 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
122 CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
123 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
124 CHECK_NOTHROW(value.get_ref<json::string_t&>());
125 CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
126 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
127 CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
128 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
129 CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
130 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
131 CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
132 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
137 using test_type = json::boolean_t;
138 json value = false;
150 CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
151 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
152 CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
153 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
154 CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
155 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
156 CHECK_NOTHROW(value.get_ref<json::boolean_t&>());
157 CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
158 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
159 CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
160 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
161 CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
162 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
167 using test_type = json::number_integer_t;
168 json value = -23;
180 CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
181 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
182 CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
183 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
184 CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
185 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
186 CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
187 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
188 CHECK_NOTHROW(value.get_ref<json::number_integer_t&>());
189 CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
190 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
191 CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
192 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
197 using test_type = json::number_unsigned_t;
198 json value = 23u;
210 CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
211 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
212 CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
213 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
214 CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
215 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
216 CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
217 "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
218 //CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
219 // "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
220 CHECK_NOTHROW(value.get_ref<json::number_unsigned_t&>());
221 CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
226 using test_type = json::number_float_t;
227 json value = 42.23;
239 CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
240 CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
241 CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
242 CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
243 CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
244 CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
245 CHECK_NOTHROW(value.get_ref<json::number_float_t&>());