1#ifndef SIMDJSON_GENERIC_ONDEMAND_VALUE_INL_H
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"
18namespace SIMDJSON_IMPLEMENTATION {
26simdjson_inline simdjson_result<T> narrow_integer(simdjson_result<uint64_t> wide)
noexcept {
28 SIMDJSON_TRY(std::move(wide).get(result));
29 if (result >
static_cast<uint64_t
>((std::numeric_limits<T>::max)())) {
return NUMBER_OUT_OF_RANGE; }
30 return static_cast<T
>(result);
38simdjson_inline simdjson_result<T> narrow_integer(simdjson_result<int64_t> wide)
noexcept {
40 SIMDJSON_TRY(std::move(wide).get(result));
41 if (result >
static_cast<int64_t
>((std::numeric_limits<T>::max)()) || result <
static_cast<int64_t
>((std::numeric_limits<T>::min)())) {
return NUMBER_OUT_OF_RANGE; }
42 return static_cast<T
>(result);
45#if SIMDJSON_SUPPORTS_FLOAT32_T
47static_assert(std::numeric_limits<float>::is_iec559 && std::numeric_limits<float>::digits == 24,
48 "get_float32() requires float to be IEEE binary32");
50#if SIMDJSON_SUPPORTS_FLOAT64_T
52static_assert(std::numeric_limits<double>::is_iec559 && std::numeric_limits<double>::digits == 53,
53 "get_float64() requires double to be IEEE binary64");
71 return object::start(iter);
74 if (iter.at_start()) {
77 return object::resume(iter);
82 return iter.get_raw_json_string();
85 return iter.get_string(allow_replacement);
87#if SIMDJSON_SUPPORTS_CHAR8_T
89 std::string_view content;
90 SIMDJSON_TRY( get_string(allow_replacement).get(content) );
91 return internal::as_u8string_view(content);
94template <
typename string_type>
96 return iter.get_string(receiver, allow_replacement);
99 return iter.get_wobbly_string();
102 return iter.get_double();
105 return iter.get_double_in_string();
108 return iter.get_float();
111 return iter.get_float_in_string();
114 return iter.get_uint64();
117 return iter.get_uint64_in_string();
120 return iter.get_int64();
123 return iter.get_int64_in_string();
126 return narrow_integer<uint32_t>(
get_uint64());
129 return narrow_integer<int32_t>(
get_int64());
132 return narrow_integer<uint16_t>(
get_uint64());
135 return narrow_integer<int16_t>(
get_int64());
141 return narrow_integer<int8_t>(
get_int64());
143#if SIMDJSON_SUPPORTS_FLOAT32_T
147 return static_cast<std::float32_t
>(result);
150#if SIMDJSON_SUPPORTS_FLOAT64_T
154 return static_cast<std::float64_t
>(result);
158 return iter.get_bool();
161 return iter.is_null();
167template<> simdjson_inline simdjson_result<std::string_view>
value::get() noexcept {
return get_string(
false); }
168#if SIMDJSON_SUPPORTS_CHAR8_T
169template<> simdjson_inline simdjson_result<std::u8string_view>
value::get() noexcept {
return get_u8string(
false); }
171template<> simdjson_inline simdjson_result<number>
value::get() noexcept {
return get_number(); }
172template<> simdjson_inline simdjson_result<double>
value::get() noexcept {
return get_double(); }
173template<> simdjson_inline simdjson_result<float>
value::get() noexcept {
return get_float(); }
174template<> simdjson_inline simdjson_result<uint64_t>
value::get() noexcept {
return get_uint64(); }
175template<> simdjson_inline simdjson_result<int64_t>
value::get() noexcept {
return get_int64(); }
176template<> simdjson_inline simdjson_result<uint32_t>
value::get() noexcept {
return get_uint32(); }
177template<> simdjson_inline simdjson_result<int32_t>
value::get() noexcept {
return get_int32(); }
178template<> simdjson_inline simdjson_result<uint16_t>
value::get() noexcept {
return get_uint16(); }
179template<> simdjson_inline simdjson_result<int16_t>
value::get() noexcept {
return get_int16(); }
180template<> simdjson_inline simdjson_result<uint8_t>
value::get() noexcept {
return get_uint8(); }
181template<> simdjson_inline simdjson_result<int8_t>
value::get() noexcept {
return get_int8(); }
182#if SIMDJSON_SUPPORTS_FLOAT32_T
183template<> simdjson_inline simdjson_result<std::float32_t>
value::get() noexcept {
return get_float32(); }
185#if SIMDJSON_SUPPORTS_FLOAT64_T
186template<> simdjson_inline simdjson_result<std::float64_t>
value::get() noexcept {
return get_float64(); }
188template<> simdjson_inline simdjson_result<bool>
value::get() noexcept {
return get_bool(); }
191template<> simdjson_warn_unused simdjson_inline
error_code value::get(array& out)
noexcept {
return get_array().get(out); }
192template<> simdjson_warn_unused simdjson_inline
error_code value::get(
object& out)
noexcept {
return get_object().get(out); }
193template<> simdjson_warn_unused simdjson_inline
error_code value::get(raw_json_string& out)
noexcept {
return get_raw_json_string().get(out); }
194template<> simdjson_warn_unused simdjson_inline
error_code value::get(std::string_view& out)
noexcept {
return get_string(
false).get(out); }
195#if SIMDJSON_SUPPORTS_CHAR8_T
196template<> simdjson_warn_unused simdjson_inline
error_code value::get(std::u8string_view& out)
noexcept {
return get_u8string(
false).get(out); }
198template<> simdjson_warn_unused simdjson_inline
error_code value::get(number& out)
noexcept {
return get_number().get(out); }
199template<> simdjson_warn_unused simdjson_inline
error_code value::get(
double& out)
noexcept {
return get_double().get(out); }
200template<> simdjson_warn_unused simdjson_inline
error_code value::get(
float& out)
noexcept {
return get_float().get(out); }
201template<> simdjson_warn_unused simdjson_inline
error_code value::get(uint64_t& out)
noexcept {
return get_uint64().get(out); }
202template<> simdjson_warn_unused simdjson_inline
error_code value::get(int64_t& out)
noexcept {
return get_int64().get(out); }
203template<> simdjson_warn_unused simdjson_inline
error_code value::get(uint32_t& out)
noexcept {
return get_uint32().get(out); }
204template<> simdjson_warn_unused simdjson_inline
error_code value::get(int32_t& out)
noexcept {
return get_int32().get(out); }
205template<> simdjson_warn_unused simdjson_inline
error_code value::get(uint16_t& out)
noexcept {
return get_uint16().get(out); }
206template<> simdjson_warn_unused simdjson_inline
error_code value::get(int16_t& out)
noexcept {
return get_int16().get(out); }
207template<> simdjson_warn_unused simdjson_inline
error_code value::get(uint8_t& out)
noexcept {
return get_uint8().get(out); }
208template<> simdjson_warn_unused simdjson_inline
error_code value::get(int8_t& out)
noexcept {
return get_int8().get(out); }
209#if SIMDJSON_SUPPORTS_FLOAT32_T
210template<> simdjson_warn_unused simdjson_inline
error_code value::get(std::float32_t& out)
noexcept {
return get_float32().get(out); }
212#if SIMDJSON_SUPPORTS_FLOAT64_T
213template<> simdjson_warn_unused simdjson_inline
error_code value::get(std::float64_t& out)
noexcept {
return get_float64().get(out); }
215template<> simdjson_warn_unused simdjson_inline
error_code value::get(
bool& out)
noexcept {
return get_bool().get(out); }
217#if SIMDJSON_EXCEPTIONS
219simdjson_inline value::operator T() noexcept(false) {
222simdjson_inline value::operator
array() noexcept(false) {
225simdjson_inline value::operator
object() noexcept(false) {
228simdjson_inline value::operator uint64_t() noexcept(false) {
231simdjson_inline value::operator int64_t() noexcept(false) {
234simdjson_inline value::operator double() noexcept(false) {
237simdjson_inline value::operator std::string_view() noexcept(false) {
238 return get_string(
false);
241 return get_raw_json_string();
243simdjson_inline value::operator bool() noexcept(false) {
249 return get_array().begin();
256 auto a = get_array();
257 answer = a.count_elements();
261 iter.move_at_start();
266 auto a = get_object();
267 answer = a.count_fields();
268 iter.move_at_start();
272 auto a = get_array();
277 return start_or_resume_object().find_field(key);
280 return start_or_resume_object().find_field(key);
284 return start_or_resume_object().find_field_unordered(key);
287 return start_or_resume_object().find_field_unordered(key);
291 return start_or_resume_object()[key];
294 return start_or_resume_object()[key];
303 auto error =
type().get(this_type);
304 if(error) {
return error; }
310 auto error =
type().get(this_type);
311 if(error) {
return error; }
317 return iter.is_negative();
321 return iter.is_integer();
324 return iter.get_number_type();
327 return iter.get_number();
331 return std::string_view(
reinterpret_cast<const char*
>(iter.peek_start()), iter.peek_start_length());
340 ondemand::array
array;
347 return object.raw_json();
355 return iter.json_iter().current_location();
359 return iter.json_iter().depth();
362inline bool is_pointer_well_formed(std::string_view json_pointer)
noexcept {
363 if (simdjson_unlikely(json_pointer.empty())) {
366 if (simdjson_unlikely(json_pointer[0] !=
'/')) {
369 size_t escape = json_pointer.find(
'~');
370 if (escape == std::string_view::npos) {
373 if (escape == json_pointer.size() - 1) {
376 if (json_pointer[escape + 1] !=
'0' && json_pointer[escape + 1] !=
'1') {
384 SIMDJSON_TRY(type().get(t));
388 return (*this).get_array().at_pointer(json_pointer);
390 return (*this).get_object().at_pointer(json_pointer);
393 if (is_pointer_well_formed(json_pointer)) {
402 SIMDJSON_TRY(type().get(t));
405 return (*this).get_array().at_path(json_path);
407 return (*this).get_object().at_path(json_path);
413#if SIMDJSON_SUPPORTS_CONCEPTS
414template <
typename Func>
415 requires std::invocable<Func, value>
417template <
typename Func>
424 if (
size_t(iter.depth()) >= iter.json_iter().parser->max_depth()) {
return DEPTH_ERROR; }
426 SIMDJSON_TRY(type().get(t));
429 return (*this).get_array().for_each_at_path_with_wildcard(json_path, std::forward<Func>(callback));
431 return (*this).get_object().for_each_at_path_with_wildcard(json_path, std::forward<Func>(callback));
443simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::simdjson_result(
444 SIMDJSON_IMPLEMENTATION::ondemand::value &&value
446 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::value>(
447 std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>(value)
451simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::simdjson_result(
454 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::value>(error)
457simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::count_elements() &
noexcept {
458 if (error()) {
return error(); }
459 return first.count_elements();
461simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::count_fields() &
noexcept {
462 if (error()) {
return error(); }
463 return first.count_fields();
465simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::at(
size_t index)
noexcept {
466 if (error()) {
return error(); }
467 return first.at(index);
469simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::begin() &
noexcept {
470 if (error()) {
return error(); }
471 return first.begin();
473simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::end() &
noexcept {
474 if (error()) {
return error(); }
479 if (error()) {
return error(); }
480 return first.find_field(key);
483 if (error()) {
return error(); }
484 return first.find_field(key);
488 if (error()) {
return error(); }
489 return first.find_field_unordered(key);
492 if (error()) {
return error(); }
493 return first.find_field_unordered(key);
496simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator[](std::string_view key)
noexcept {
497 if (error()) {
return error(); }
500simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator[](
const char *key)
noexcept {
501 if (error()) {
return error(); }
505simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_array() noexcept {
506 if (error()) {
return error(); }
507 return first.get_array();
509simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_object() noexcept {
510 if (error()) {
return error(); }
511 return first.get_object();
513simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint64() noexcept {
514 if (error()) {
return error(); }
515 return first.get_uint64();
517simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint64_in_string() noexcept {
518 if (error()) {
return error(); }
519 return first.get_uint64_in_string();
521simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int64() noexcept {
522 if (error()) {
return error(); }
523 return first.get_int64();
525simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int64_in_string() noexcept {
526 if (error()) {
return error(); }
527 return first.get_int64_in_string();
529simdjson_inline simdjson_result<uint32_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint32() noexcept {
530 if (error()) {
return error(); }
531 return first.get_uint32();
533simdjson_inline simdjson_result<int32_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int32() noexcept {
534 if (error()) {
return error(); }
535 return first.get_int32();
537simdjson_inline simdjson_result<uint16_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint16() noexcept {
538 if (error()) {
return error(); }
539 return first.get_uint16();
541simdjson_inline simdjson_result<int16_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int16() noexcept {
542 if (error()) {
return error(); }
543 return first.get_int16();
545simdjson_inline simdjson_result<uint8_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint8() noexcept {
546 if (error()) {
return error(); }
547 return first.get_uint8();
549simdjson_inline simdjson_result<int8_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int8() noexcept {
550 if (error()) {
return error(); }
551 return first.get_int8();
553simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_double() noexcept {
554 if (error()) {
return error(); }
555 return first.get_double();
557simdjson_inline simdjson_result<float> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_float() noexcept {
558 if (error()) {
return error(); }
559 return first.get_float();
561simdjson_inline simdjson_result<float> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_float_in_string() noexcept {
562 if (error()) {
return error(); }
563 return first.get_float_in_string();
565#if SIMDJSON_SUPPORTS_FLOAT32_T
566simdjson_inline simdjson_result<std::float32_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_float32() noexcept {
567 if (error()) {
return error(); }
568 return first.get_float32();
571#if SIMDJSON_SUPPORTS_FLOAT64_T
572simdjson_inline simdjson_result<std::float64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_float64() noexcept {
573 if (error()) {
return error(); }
574 return first.get_float64();
577simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_double_in_string() noexcept {
578 if (error()) {
return error(); }
579 return first.get_double_in_string();
581simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_string(
bool allow_replacement)
noexcept {
582 if (error()) {
return error(); }
583 return first.get_string(allow_replacement);
585#if SIMDJSON_SUPPORTS_CHAR8_T
586simdjson_inline simdjson_result<std::u8string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_u8string(
bool allow_replacement)
noexcept {
587 if (error()) {
return error(); }
588 return first.get_u8string(allow_replacement);
591template <
typename string_type>
592simdjson_inline
error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_string(string_type& receiver,
bool allow_replacement)
noexcept {
593 if (error()) {
return error(); }
594 return first.get_string(receiver, allow_replacement);
596simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_wobbly_string() noexcept {
597 if (error()) {
return error(); }
598 return first.get_wobbly_string();
600simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_raw_json_string() noexcept {
601 if (error()) {
return error(); }
602 return first.get_raw_json_string();
604simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_bool() noexcept {
605 if (error()) {
return error(); }
606 return first.get_bool();
608simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_null() noexcept {
609 if (error()) {
return error(); }
610 return first.is_null();
613template<> simdjson_inline
error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>(SIMDJSON_IMPLEMENTATION::ondemand::value &out)
noexcept {
614 if (error()) {
return error(); }
620#if SIMDJSON_SUPPORTS_CONCEPTS
621 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::value>)
626 if (error()) {
return error(); }
627 return first.get<T>();
630#if SIMDJSON_SUPPORTS_CONCEPTS
631 noexcept(nothrow_gettable<T, SIMDJSON_IMPLEMENTATION::ondemand::value>)
636 if (error()) {
return error(); }
637 return first.get<T>(out);
640template<> simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>() noexcept {
641 if (error()) {
return error(); }
642 return std::move(first);
646 if (error()) {
return error(); }
650 if (error()) {
return error(); }
651 return first.is_scalar();
653simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_string() noexcept {
654 if (error()) {
return error(); }
655 return first.is_string();
657simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_negative() noexcept {
658 if (error()) {
return error(); }
659 return first.is_negative();
661simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_integer() noexcept {
662 if (error()) {
return error(); }
663 return first.is_integer();
665simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_number_type() noexcept {
666 if (error()) {
return error(); }
667 return first.get_number_type();
669simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_number() noexcept {
670 if (error()) {
return error(); }
671 return first.get_number();
673#if SIMDJSON_EXCEPTIONS
675simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator T() noexcept(false) {
676 if (error()) {
throw simdjson_error(error()); }
677 return first.get<T>();
679simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() noexcept(false) {
680 if (error()) {
throw simdjson_error(error()); }
683simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() noexcept(false) {
684 if (error()) {
throw simdjson_error(error()); }
687simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator uint64_t() noexcept(false) {
688 if (error()) {
throw simdjson_error(error()); }
691simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator int64_t() noexcept(false) {
692 if (error()) {
throw simdjson_error(error()); }
695simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator double() noexcept(false) {
696 if (error()) {
throw simdjson_error(error()); }
699simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator std::string_view() noexcept(false) {
700 if (error()) {
throw simdjson_error(error()); }
703simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false) {
704 if (error()) {
throw simdjson_error(error()); }
707simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator bool() noexcept(false) {
708 if (error()) {
throw simdjson_error(error()); }
714 if (error()) {
return error(); }
715 return first.raw_json_token();
719 if (error()) {
return error(); }
720 return first.raw_json();
724 if (error()) {
return error(); }
725 return first.current_location();
729 if (error()) {
return error(); }
730 return first.current_depth();
734 std::string_view json_pointer)
noexcept {
738 return first.at_pointer(json_pointer);
741simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::at_path(
742 std::string_view json_path)
noexcept {
746 return first.at_path(json_path);
749#if SIMDJSON_SUPPORTS_CONCEPTS
750template <
typename Func>
751 requires std::invocable<Func, SIMDJSON_IMPLEMENTATION::ondemand::value>
753template <
typename Func>
755inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::for_each_at_path_with_wildcard(
756 std::string_view json_path, Func&& callback)
noexcept {
760 return first.for_each_at_path_with_wildcard(json_path, std::forward<Func>(callback));
A forward-only JSON array.
static simdjson_inline simdjson_result< array > start(value_iterator &iter) noexcept
Begin array iteration.
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...
A forward-only JSON object field iterator.
A string escaped per JSON rules, terminated with quote (").
An ephemeral JSON value returned during iteration.
static simdjson_inline value start(const value_iterator &iter) noexcept
Start a value at the current position.
simdjson_inline simdjson_result< bool > is_null() noexcept
Checks if this JSON value is null.
simdjson_inline simdjson_result< const char * > current_location() noexcept
Returns the current location in the document if in bounds.
simdjson_inline simdjson_result< float > get_float_in_string() noexcept
Cast this JSON value (inside string) to a float (binary32).
simdjson_inline simdjson_result< value > find_field(std::string_view key) noexcept
Look up a field by name on an object (order-sensitive).
simdjson_inline simdjson_result< T > get() noexcept
Get this value as the given type.
simdjson_inline bool is_negative() noexcept
Checks whether the value is a negative number.
simdjson_inline simdjson_result< float > get_float() noexcept
Cast this JSON value to a float (binary32).
simdjson_inline simdjson_result< number_type > get_number_type() noexcept
Determine the number type (integer or floating-point number) as quickly as possible.
simdjson_inline simdjson_result< array > get_array() noexcept
Cast this JSON value to an array.
simdjson_inline std::string_view raw_json_token() noexcept
Get the raw JSON for this token.
simdjson_inline simdjson_result< object > get_object() noexcept
Cast this JSON value to an object.
simdjson_inline simdjson_result< uint8_t > get_uint8() noexcept
Cast this JSON value to an 8-bit unsigned integer.
simdjson_inline simdjson_result< size_t > count_elements() &noexcept
This method scans the array and counts the number of elements.
simdjson_inline simdjson_result< int64_t > get_int64_in_string() noexcept
Cast this JSON value (inside string) to a signed integer.
simdjson_inline simdjson_result< size_t > count_fields() &noexcept
This method scans the object and counts the number of key-value pairs.
simdjson_inline simdjson_result< bool > is_integer() noexcept
Checks whether the value is an integer number.
simdjson_inline simdjson_result< int8_t > get_int8() noexcept
Cast this JSON value to an 8-bit signed integer.
simdjson_inline simdjson_result< array_iterator > end() &noexcept
Sentinel representing the end of the array.
simdjson_inline simdjson_result< value > at_path(std::string_view at_path) noexcept
Get the value associated with the given JSONPath expression.
simdjson_inline simdjson_result< object > start_or_resume_object() noexcept
Get the object, starting or resuming it as necessary.
simdjson_inline simdjson_result< array_iterator > begin() &noexcept
Begin array iteration.
simdjson_inline simdjson_result< uint64_t > get_uint64_in_string() noexcept
Cast this JSON value (inside string) to a unsigned integer.
simdjson_inline int32_t current_depth() const noexcept
Returns the current depth in the document if in bounds.
simdjson_inline simdjson_result< int16_t > get_int16() noexcept
Cast this JSON value to a 16-bit signed integer.
simdjson_inline simdjson_result< bool > is_scalar() noexcept
Checks whether the value is a scalar (string, number, null, Boolean).
simdjson_inline simdjson_result< std::string_view > raw_json() noexcept
Get a string_view pointing at this value in the JSON document.
static simdjson_inline value resume(const value_iterator &iter) noexcept
Resume a value.
simdjson_inline simdjson_result< double > get_double() noexcept
Cast this JSON value to a double.
simdjson_inline simdjson_result< std::string_view > get_string(bool allow_replacement=false) noexcept
Cast this JSON value to a string.
simdjson_inline simdjson_result< bool > get_bool() noexcept
Cast this JSON value to a bool.
simdjson_warn_unused simdjson_inline simdjson_result< number > get_number() noexcept
Attempt to parse an ondemand::number.
simdjson_inline simdjson_result< value > at_pointer(std::string_view json_pointer) noexcept
Get the value associated with the given JSON pointer.
simdjson_inline simdjson_result< std::string_view > get_wobbly_string() noexcept
Cast this JSON value to a "wobbly" string.
simdjson_inline simdjson_result< int64_t > get_int64() noexcept
Cast this JSON value to a signed integer.
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.
simdjson_inline simdjson_result< double > get_double_in_string() noexcept
Cast this JSON value (inside string) to a double.
simdjson_inline simdjson_result< raw_json_string > get_raw_json_string() noexcept
Cast this JSON value to a raw_json_string.
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.
simdjson_inline simdjson_result< value > at(size_t index) noexcept
Get the value at the given index in the array.
simdjson_inline simdjson_result< uint16_t > get_uint16() noexcept
Cast this JSON value to a 16-bit unsigned integer.
simdjson_inline simdjson_result< uint64_t > get_uint64() noexcept
Cast this JSON value to an unsigned integer.
simdjson_inline simdjson_result< int32_t > get_int32() noexcept
Cast this JSON value to a 32-bit signed integer.
simdjson_inline simdjson_result< uint32_t > get_uint32() noexcept
Cast this JSON value to a 32-bit unsigned integer.
simdjson_inline simdjson_result< bool > is_string() noexcept
Checks whether the value is a string.
json_type
The type of a JSON value.
@ object
A JSON object ( { "a": 1, "b" 2, ... } )
@ string
A JSON string ( "a" or "hello world\n" ...)
@ array
A JSON array ( [ 1, 2, 3 ... ] )
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
@ DEPTH_ERROR
Your document exceeds the user-specified depth limitation.
@ NO_SUCH_FIELD
JSON field not found in object.
@ NUMBER_OUT_OF_RANGE
JSON number does not fit in 64 bits.
@ INVALID_JSON_POINTER
Invalid JSON pointer syntax.
The result of a simdjson operation that could fail.
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.