simdjson 4.6.3
Ridiculously Fast JSON
Loading...
Searching...
No Matches
value-inl.h
1#ifndef SIMDJSON_GENERIC_ONDEMAND_VALUE_INL_H
2
3#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4#define SIMDJSON_GENERIC_ONDEMAND_VALUE_INL_H
5#include "simdjson/generic/ondemand/base.h"
6#include "simdjson/generic/ondemand/array.h"
7#include "simdjson/generic/ondemand/array_iterator.h"
8#include "simdjson/generic/ondemand/json_iterator.h"
9#include "simdjson/generic/ondemand/json_type.h"
10#include "simdjson/generic/ondemand/object.h"
11#include "simdjson/generic/ondemand/raw_json_string.h"
12#include "simdjson/generic/ondemand/value.h"
13#endif // SIMDJSON_CONDITIONAL_INCLUDE
14
15#include <limits>
16
17namespace simdjson {
18namespace SIMDJSON_IMPLEMENTATION {
19namespace ondemand {
20
21simdjson_inline value::value(const value_iterator &_iter) noexcept
22 : iter{_iter}
23{
24}
25simdjson_inline value value::start(const value_iterator &iter) noexcept {
26 return iter;
27}
28simdjson_inline value value::resume(const value_iterator &iter) noexcept {
29 return iter;
30}
31
32simdjson_inline simdjson_result<array> value::get_array() noexcept {
33 return array::start(iter);
34}
35simdjson_inline simdjson_result<object> value::get_object() noexcept {
36 return object::start(iter);
37}
39 if (iter.at_start()) {
40 return get_object();
41 } else {
42 return object::resume(iter);
43 }
44}
45
47 return iter.get_raw_json_string();
48}
49simdjson_inline simdjson_result<std::string_view> value::get_string(bool allow_replacement) noexcept {
50 return iter.get_string(allow_replacement);
51}
52template <typename string_type>
53simdjson_warn_unused simdjson_inline error_code value::get_string(string_type& receiver, bool allow_replacement) noexcept {
54 return iter.get_string(receiver, allow_replacement);
55}
57 return iter.get_wobbly_string();
58}
59simdjson_inline simdjson_result<double> value::get_double() noexcept {
60 return iter.get_double();
61}
63 return iter.get_double_in_string();
64}
65simdjson_inline simdjson_result<uint64_t> value::get_uint64() noexcept {
66 return iter.get_uint64();
67}
69 return iter.get_uint64_in_string();
70}
71simdjson_inline simdjson_result<int64_t> value::get_int64() noexcept {
72 return iter.get_int64();
73}
75 return iter.get_int64_in_string();
76}
77simdjson_inline simdjson_result<uint32_t> value::get_uint32() noexcept {
78 uint64_t result;
79 SIMDJSON_TRY(get_uint64().get(result));
80 if (result > (std::numeric_limits<uint32_t>::max)()) { return NUMBER_OUT_OF_RANGE; }
81 return static_cast<uint32_t>(result);
82}
83simdjson_inline simdjson_result<int32_t> value::get_int32() noexcept {
84 int64_t result;
85 SIMDJSON_TRY(get_int64().get(result));
86 if (result > (std::numeric_limits<int32_t>::max)() || result < (std::numeric_limits<int32_t>::min)()) { return NUMBER_OUT_OF_RANGE; }
87 return static_cast<int32_t>(result);
88}
89simdjson_inline simdjson_result<bool> value::get_bool() noexcept {
90 return iter.get_bool();
91}
92simdjson_inline simdjson_result<bool> value::is_null() noexcept {
93 return iter.is_null();
94}
95
96template<> simdjson_inline simdjson_result<array> value::get() noexcept { return get_array(); }
97template<> simdjson_inline simdjson_result<object> value::get() noexcept { return get_object(); }
98template<> simdjson_inline simdjson_result<raw_json_string> value::get() noexcept { return get_raw_json_string(); }
99template<> simdjson_inline simdjson_result<std::string_view> value::get() noexcept { return get_string(false); }
100template<> simdjson_inline simdjson_result<number> value::get() noexcept { return get_number(); }
101template<> simdjson_inline simdjson_result<double> value::get() noexcept { return get_double(); }
102template<> simdjson_inline simdjson_result<uint64_t> value::get() noexcept { return get_uint64(); }
103template<> simdjson_inline simdjson_result<int64_t> value::get() noexcept { return get_int64(); }
104template<> simdjson_inline simdjson_result<uint32_t> value::get() noexcept { return get_uint32(); }
105template<> simdjson_inline simdjson_result<int32_t> value::get() noexcept { return get_int32(); }
106template<> simdjson_inline simdjson_result<bool> value::get() noexcept { return get_bool(); }
107
108
109template<> simdjson_warn_unused simdjson_inline error_code value::get(array& out) noexcept { return get_array().get(out); }
110template<> simdjson_warn_unused simdjson_inline error_code value::get(object& out) noexcept { return get_object().get(out); }
111template<> simdjson_warn_unused simdjson_inline error_code value::get(raw_json_string& out) noexcept { return get_raw_json_string().get(out); }
112template<> simdjson_warn_unused simdjson_inline error_code value::get(std::string_view& out) noexcept { return get_string(false).get(out); }
113template<> simdjson_warn_unused simdjson_inline error_code value::get(number& out) noexcept { return get_number().get(out); }
114template<> simdjson_warn_unused simdjson_inline error_code value::get(double& out) noexcept { return get_double().get(out); }
115template<> simdjson_warn_unused simdjson_inline error_code value::get(uint64_t& out) noexcept { return get_uint64().get(out); }
116template<> simdjson_warn_unused simdjson_inline error_code value::get(int64_t& out) noexcept { return get_int64().get(out); }
117template<> simdjson_warn_unused simdjson_inline error_code value::get(uint32_t& out) noexcept { return get_uint32().get(out); }
118template<> simdjson_warn_unused simdjson_inline error_code value::get(int32_t& out) noexcept { return get_int32().get(out); }
119template<> simdjson_warn_unused simdjson_inline error_code value::get(bool& out) noexcept { return get_bool().get(out); }
120
121#if SIMDJSON_EXCEPTIONS
122template <class T>
123simdjson_inline value::operator T() noexcept(false) {
124 return get<T>();
125}
126simdjson_inline value::operator array() noexcept(false) {
127 return get_array();
128}
129simdjson_inline value::operator object() noexcept(false) {
130 return get_object();
131}
132simdjson_inline value::operator uint64_t() noexcept(false) {
133 return get_uint64();
134}
135simdjson_inline value::operator int64_t() noexcept(false) {
136 return get_int64();
137}
138simdjson_inline value::operator double() noexcept(false) {
139 return get_double();
140}
141simdjson_inline value::operator std::string_view() noexcept(false) {
142 return get_string(false);
143}
144simdjson_inline value::operator raw_json_string() noexcept(false) {
145 return get_raw_json_string();
146}
147simdjson_inline value::operator bool() noexcept(false) {
148 return get_bool();
149}
150#endif
151
152simdjson_inline simdjson_result<array_iterator> value::begin() & noexcept {
153 return get_array().begin();
154}
155simdjson_inline simdjson_result<array_iterator> value::end() & noexcept {
156 return {};
157}
158simdjson_inline simdjson_result<size_t> value::count_elements() & noexcept {
160 auto a = get_array();
161 answer = a.count_elements();
162 // count_elements leaves you pointing inside the array, at the first element.
163 // We need to move back so that the user can create a new array (which requires that
164 // we point at '[').
165 iter.move_at_start();
166 return answer;
167}
168simdjson_inline simdjson_result<size_t> value::count_fields() & noexcept {
170 auto a = get_object();
171 answer = a.count_fields();
172 iter.move_at_start();
173 return answer;
174}
175simdjson_inline simdjson_result<value> value::at(size_t index) noexcept {
176 auto a = get_array();
177 return a.at(index);
178}
179
180simdjson_inline simdjson_result<value> value::find_field(std::string_view key) noexcept {
181 return start_or_resume_object().find_field(key);
182}
183simdjson_inline simdjson_result<value> value::find_field(const char *key) noexcept {
184 return start_or_resume_object().find_field(key);
185}
186
187simdjson_inline simdjson_result<value> value::find_field_unordered(std::string_view key) noexcept {
188 return start_or_resume_object().find_field_unordered(key);
189}
190simdjson_inline simdjson_result<value> value::find_field_unordered(const char *key) noexcept {
191 return start_or_resume_object().find_field_unordered(key);
192}
193
194simdjson_inline simdjson_result<value> value::operator[](std::string_view key) noexcept {
195 return start_or_resume_object()[key];
196}
197simdjson_inline simdjson_result<value> value::operator[](const char *key) noexcept {
198 return start_or_resume_object()[key];
199}
200
201simdjson_inline simdjson_result<json_type> value::type() noexcept {
202 return iter.type();
203}
204
205simdjson_inline simdjson_result<bool> value::is_scalar() noexcept {
206 json_type this_type;
207 auto error = type().get(this_type);
208 if(error) { return error; }
209 return ! ((this_type == json_type::array) || (this_type == json_type::object));
210}
211
212simdjson_inline simdjson_result<bool> value::is_string() noexcept {
213 json_type this_type;
214 auto error = type().get(this_type);
215 if(error) { return error; }
216 return (this_type == json_type::string);
217}
218
219
220simdjson_inline bool value::is_negative() noexcept {
221 return iter.is_negative();
222}
223
224simdjson_inline simdjson_result<bool> value::is_integer() noexcept {
225 return iter.is_integer();
226}
227simdjson_warn_unused simdjson_inline simdjson_result<number_type> value::get_number_type() noexcept {
228 return iter.get_number_type();
229}
230simdjson_warn_unused simdjson_inline simdjson_result<number> value::get_number() noexcept {
231 return iter.get_number();
232}
233
234simdjson_inline std::string_view value::raw_json_token() noexcept {
235 return std::string_view(reinterpret_cast<const char*>(iter.peek_start()), iter.peek_start_length());
236}
237
239 json_type t;
240 SIMDJSON_TRY(type().get(t));
241 switch (t)
242 {
243 case json_type::array: {
244 ondemand::array array;
245 SIMDJSON_TRY(get_array().get(array));
246 return array.raw_json();
247 }
248 case json_type::object: {
249 ondemand::object object;
250 SIMDJSON_TRY(get_object().get(object));
251 return object.raw_json();
252 }
253 default:
254 return raw_json_token();
255 }
256}
257
259 return iter.json_iter().current_location();
260}
261
262simdjson_inline int32_t value::current_depth() const noexcept{
263 return iter.json_iter().depth();
264}
265
266inline bool is_pointer_well_formed(std::string_view json_pointer) noexcept {
267 if (simdjson_unlikely(json_pointer.empty())) { // can't be
268 return false;
269 }
270 if (simdjson_unlikely(json_pointer[0] != '/')) {
271 return false;
272 }
273 size_t escape = json_pointer.find('~');
274 if (escape == std::string_view::npos) {
275 return true;
276 }
277 if (escape == json_pointer.size() - 1) {
278 return false;
279 }
280 if (json_pointer[escape + 1] != '0' && json_pointer[escape + 1] != '1') {
281 return false;
282 }
283 return true;
284}
285
286simdjson_inline simdjson_result<value> value::at_pointer(std::string_view json_pointer) noexcept {
287 json_type t;
288 SIMDJSON_TRY(type().get(t));
289 switch (t)
290 {
291 case json_type::array:
292 return (*this).get_array().at_pointer(json_pointer);
294 return (*this).get_object().at_pointer(json_pointer);
295 default:
296 // a non-empty string can be invalid, or accessing a primitive (issue 2154)
297 if (is_pointer_well_formed(json_pointer)) {
298 return NO_SUCH_FIELD;
299 }
301 }
302}
303
304simdjson_inline simdjson_result<value> value::at_path(std::string_view json_path) noexcept {
305 json_type t;
306 SIMDJSON_TRY(type().get(t));
307 switch (t) {
308 case json_type::array:
309 return (*this).get_array().at_path(json_path);
311 return (*this).get_object().at_path(json_path);
312 default:
314 }
315}
316
317#if SIMDJSON_SUPPORTS_CONCEPTS
318template <typename Func>
319 requires std::invocable<Func, value>
320#else
321template <typename Func>
322#endif
323inline error_code value::for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback) noexcept {
324 json_type t;
325 SIMDJSON_TRY(type().get(t));
326 switch (t) {
327 case json_type::array:
328 return (*this).get_array().for_each_at_path_with_wildcard(json_path, std::forward<Func>(callback));
330 return (*this).get_object().for_each_at_path_with_wildcard(json_path, std::forward<Func>(callback));
331 default:
333 }
334}
335
336} // namespace ondemand
337} // namespace SIMDJSON_IMPLEMENTATION
338} // namespace simdjson
339
340namespace simdjson {
341
342simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::simdjson_result(
343 SIMDJSON_IMPLEMENTATION::ondemand::value &&value
344) noexcept :
345 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::value>(
346 std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>(value)
347 )
348{
349}
350simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::simdjson_result(
351 error_code error
352) noexcept :
353 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::value>(error)
354{
355}
356simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::count_elements() & noexcept {
357 if (error()) { return error(); }
358 return first.count_elements();
359}
360simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::count_fields() & noexcept {
361 if (error()) { return error(); }
362 return first.count_fields();
363}
364simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::at(size_t index) noexcept {
365 if (error()) { return error(); }
366 return first.at(index);
367}
368simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::begin() & noexcept {
369 if (error()) { return error(); }
370 return first.begin();
371}
372simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::end() & noexcept {
373 if (error()) { return error(); }
374 return {};
375}
376
378 if (error()) { return error(); }
379 return first.find_field(key);
380}
382 if (error()) { return error(); }
383 return first.find_field(key);
384}
385
387 if (error()) { return error(); }
388 return first.find_field_unordered(key);
389}
391 if (error()) { return error(); }
392 return first.find_field_unordered(key);
393}
394
395simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator[](std::string_view key) noexcept {
396 if (error()) { return error(); }
397 return first[key];
398}
399simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator[](const char *key) noexcept {
400 if (error()) { return error(); }
401 return first[key];
402}
403
404simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_array() noexcept {
405 if (error()) { return error(); }
406 return first.get_array();
407}
408simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_object() noexcept {
409 if (error()) { return error(); }
410 return first.get_object();
411}
412simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint64() noexcept {
413 if (error()) { return error(); }
414 return first.get_uint64();
415}
416simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint64_in_string() noexcept {
417 if (error()) { return error(); }
418 return first.get_uint64_in_string();
419}
420simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int64() noexcept {
421 if (error()) { return error(); }
422 return first.get_int64();
423}
424simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int64_in_string() noexcept {
425 if (error()) { return error(); }
426 return first.get_int64_in_string();
427}
428simdjson_inline simdjson_result<uint32_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint32() noexcept {
429 if (error()) { return error(); }
430 return first.get_uint32();
431}
432simdjson_inline simdjson_result<int32_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int32() noexcept {
433 if (error()) { return error(); }
434 return first.get_int32();
435}
436simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_double() noexcept {
437 if (error()) { return error(); }
438 return first.get_double();
439}
440simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_double_in_string() noexcept {
441 if (error()) { return error(); }
442 return first.get_double_in_string();
443}
444simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_string(bool allow_replacement) noexcept {
445 if (error()) { return error(); }
446 return first.get_string(allow_replacement);
447}
448template <typename string_type>
449simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_string(string_type& receiver, bool allow_replacement) noexcept {
450 if (error()) { return error(); }
451 return first.get_string(receiver, allow_replacement);
452}
453simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_wobbly_string() noexcept {
454 if (error()) { return error(); }
455 return first.get_wobbly_string();
456}
457simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_raw_json_string() noexcept {
458 if (error()) { return error(); }
459 return first.get_raw_json_string();
460}
461simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_bool() noexcept {
462 if (error()) { return error(); }
463 return first.get_bool();
464}
465simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_null() noexcept {
466 if (error()) { return error(); }
467 return first.is_null();
468}
469
470template<> simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>(SIMDJSON_IMPLEMENTATION::ondemand::value &out) noexcept {
471 if (error()) { return error(); }
472 out = first;
473 return SUCCESS;
474}
475
476template<typename T> simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get() noexcept {
477 if (error()) { return error(); }
478 return first.get<T>();
479}
480template<typename T> simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get(T &out) noexcept {
481 if (error()) { return error(); }
482 return first.get<T>(out);
483}
484
485template<> simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>() noexcept {
486 if (error()) { return error(); }
487 return std::move(first);
488}
489
491 if (error()) { return error(); }
492 return first.type();
493}
495 if (error()) { return error(); }
496 return first.is_scalar();
497}
498simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_string() noexcept {
499 if (error()) { return error(); }
500 return first.is_string();
501}
502simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_negative() noexcept {
503 if (error()) { return error(); }
504 return first.is_negative();
505}
506simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_integer() noexcept {
507 if (error()) { return error(); }
508 return first.is_integer();
509}
510simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_number_type() noexcept {
511 if (error()) { return error(); }
512 return first.get_number_type();
513}
514simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_number() noexcept {
515 if (error()) { return error(); }
516 return first.get_number();
517}
518#if SIMDJSON_EXCEPTIONS
519template <class T>
520simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator T() noexcept(false) {
521 if (error()) { throw simdjson_error(error()); }
522 return first.get<T>();
523}
524simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() noexcept(false) {
525 if (error()) { throw simdjson_error(error()); }
526 return first;
527}
528simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() noexcept(false) {
529 if (error()) { throw simdjson_error(error()); }
530 return first;
531}
532simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator uint64_t() noexcept(false) {
533 if (error()) { throw simdjson_error(error()); }
534 return first;
535}
536simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator int64_t() noexcept(false) {
537 if (error()) { throw simdjson_error(error()); }
538 return first;
539}
540simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator double() noexcept(false) {
541 if (error()) { throw simdjson_error(error()); }
542 return first;
543}
544simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator std::string_view() noexcept(false) {
545 if (error()) { throw simdjson_error(error()); }
546 return first;
547}
548simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false) {
549 if (error()) { throw simdjson_error(error()); }
550 return first;
551}
552simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator bool() noexcept(false) {
553 if (error()) { throw simdjson_error(error()); }
554 return first;
555}
556#endif
557
559 if (error()) { return error(); }
560 return first.raw_json_token();
561}
562
564 if (error()) { return error(); }
565 return first.raw_json();
566}
567
569 if (error()) { return error(); }
570 return first.current_location();
571}
572
574 if (error()) { return error(); }
575 return first.current_depth();
576}
577
579 std::string_view json_pointer) noexcept {
580 if (error()) {
581 return error();
582 }
583 return first.at_pointer(json_pointer);
584}
585
586simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::at_path(
587 std::string_view json_path) noexcept {
588 if (error()) {
589 return error();
590 }
591 return first.at_path(json_path);
592}
593
594#if SIMDJSON_SUPPORTS_CONCEPTS
595template <typename Func>
596 requires std::invocable<Func, SIMDJSON_IMPLEMENTATION::ondemand::value>
597#else
598template <typename Func>
599#endif
600inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::for_each_at_path_with_wildcard(
601 std::string_view json_path, Func&& callback) noexcept {
602 if (error()) {
603 return error();
604 }
605 return first.for_each_at_path_with_wildcard(json_path, std::forward<Func>(callback));
606}
607
608} // namespace simdjson
609
610#endif // SIMDJSON_GENERIC_ONDEMAND_VALUE_INL_H
static simdjson_inline simdjson_result< array > start(value_iterator &iter) noexcept
Begin array iteration.
Definition array-inl.h:61
simdjson_inline simdjson_result< std::string_view > raw_json() noexcept
Consumes the array and returns a string_view instance corresponding to the array as represented in JS...
Definition array-inl.h:94
A forward-only JSON object field iterator.
Definition object.h:21
A string escaped per JSON rules, terminated with quote (").
An ephemeral JSON value returned during iteration.
Definition value.h:22
static simdjson_inline value start(const value_iterator &iter) noexcept
Start a value at the current position.
Definition value-inl.h:25
simdjson_inline simdjson_result< bool > is_null() noexcept
Checks if this JSON value is null.
Definition value-inl.h:92
simdjson_inline simdjson_result< const char * > current_location() noexcept
Returns the current location in the document if in bounds.
Definition value-inl.h:258
simdjson_inline simdjson_result< value > find_field(std::string_view key) noexcept
Look up a field by name on an object (order-sensitive).
Definition value-inl.h:180
simdjson_inline simdjson_result< T > get() noexcept
Get this value as the given type.
Definition value.h:44
simdjson_inline bool is_negative() noexcept
Checks whether the value is a negative number.
Definition value-inl.h:220
simdjson_inline simdjson_result< number_type > get_number_type() noexcept
Determine the number type (integer or floating-point number) as quickly as possible.
Definition value-inl.h:227
simdjson_inline simdjson_result< array > get_array() noexcept
Cast this JSON value to an array.
Definition value-inl.h:32
simdjson_inline std::string_view raw_json_token() noexcept
Get the raw JSON for this token.
Definition value-inl.h:234
simdjson_inline simdjson_result< object > get_object() noexcept
Cast this JSON value to an object.
Definition value-inl.h:35
simdjson_inline simdjson_result< size_t > count_elements() &noexcept
This method scans the array and counts the number of elements.
Definition value-inl.h:158
simdjson_inline simdjson_result< int64_t > get_int64_in_string() noexcept
Cast this JSON value (inside string) to a signed integer.
Definition value-inl.h:74
simdjson_inline simdjson_result< size_t > count_fields() &noexcept
This method scans the object and counts the number of key-value pairs.
Definition value-inl.h:168
simdjson_inline simdjson_result< bool > is_integer() noexcept
Checks whether the value is an integer number.
Definition value-inl.h:224
simdjson_inline simdjson_result< array_iterator > end() &noexcept
Sentinel representing the end of the array.
Definition value-inl.h:155
simdjson_inline simdjson_result< value > at_path(std::string_view at_path) noexcept
Get the value associated with the given JSONPath expression.
Definition value-inl.h:304
simdjson_inline simdjson_result< object > start_or_resume_object() noexcept
Get the object, starting or resuming it as necessary.
Definition value-inl.h:38
simdjson_inline simdjson_result< array_iterator > begin() &noexcept
Begin array iteration.
Definition value-inl.h:152
simdjson_inline simdjson_result< uint64_t > get_uint64_in_string() noexcept
Cast this JSON value (inside string) to a unsigned integer.
Definition value-inl.h:68
simdjson_inline int32_t current_depth() const noexcept
Returns the current depth in the document if in bounds.
Definition value-inl.h:262
simdjson_inline simdjson_result< bool > is_scalar() noexcept
Checks whether the value is a scalar (string, number, null, Boolean).
Definition value-inl.h:205
simdjson_inline simdjson_result< std::string_view > raw_json() noexcept
Get a string_view pointing at this value in the JSON document.
Definition value-inl.h:238
static simdjson_inline value resume(const value_iterator &iter) noexcept
Resume a value.
Definition value-inl.h:28
simdjson_inline simdjson_result< double > get_double() noexcept
Cast this JSON value to a double.
Definition value-inl.h:59
simdjson_inline simdjson_result< std::string_view > get_string(bool allow_replacement=false) noexcept
Cast this JSON value to a string.
Definition value-inl.h:49
simdjson_inline simdjson_result< bool > get_bool() noexcept
Cast this JSON value to a bool.
Definition value-inl.h:89
simdjson_warn_unused simdjson_inline simdjson_result< number > get_number() noexcept
Attempt to parse an ondemand::number.
Definition value-inl.h:230
simdjson_inline simdjson_result< value > at_pointer(std::string_view json_pointer) noexcept
Get the value associated with the given JSON pointer.
Definition value-inl.h:286
simdjson_inline simdjson_result< std::string_view > get_wobbly_string() noexcept
Cast this JSON value to a "wobbly" string.
Definition value-inl.h:56
simdjson_inline simdjson_result< int64_t > get_int64() noexcept
Cast this JSON value to a signed integer.
Definition value-inl.h:71
simdjson_inline value() noexcept=default
Create a new invalid value.
simdjson_inline error_code for_each_at_path_with_wildcard(std::string_view json_path, Func &&callback) noexcept
Call the provided callback for each value matching the given JSONPath expression with wildcard suppor...
simdjson_inline simdjson_result< json_type > type() noexcept
Get the type of this JSON value.
Definition value-inl.h:201
simdjson_inline simdjson_result< double > get_double_in_string() noexcept
Cast this JSON value (inside string) to a double.
Definition value-inl.h:62
simdjson_inline simdjson_result< raw_json_string > get_raw_json_string() noexcept
Cast this JSON value to a raw_json_string.
Definition value-inl.h:46
simdjson_inline simdjson_result< value > find_field_unordered(std::string_view key) noexcept
Look up a field by name on an object, without regard to key order.
Definition value-inl.h:187
simdjson_inline simdjson_result< value > at(size_t index) noexcept
Get the value at the given index in the array.
Definition value-inl.h:175
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
Cast this JSON value to an unsigned integer.
Definition value-inl.h:65
simdjson_inline simdjson_result< int32_t > get_int32() noexcept
Cast this JSON value to a 32-bit signed integer.
Definition value-inl.h:83
simdjson_inline simdjson_result< uint32_t > get_uint32() noexcept
Cast this JSON value to a 32-bit unsigned integer.
Definition value-inl.h:77
simdjson_inline simdjson_result< bool > is_string() noexcept
Checks whether the value is a string.
Definition value-inl.h:212
@ object
A JSON object ( { "a": 1, "b" 2, ... } )
@ string
A JSON string ( "a" or "hello world\n" ...)
The top level simdjson namespace, containing everything the library provides.
Definition base.h:8
error_code
All possible errors returned by simdjson.
Definition error.h:19
@ NO_SUCH_FIELD
JSON field not found in object.
Definition error.h:40
@ NUMBER_OUT_OF_RANGE
JSON number does not fit in 64 bits.
Definition error.h:38
@ SUCCESS
No error.
Definition error.h:20
@ INVALID_JSON_POINTER
Invalid JSON pointer syntax.
Definition error.h:42
The result of a simdjson operation that could fail.
Definition error.h:280
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.
Definition error-inl.h:163