simdjson 4.6.11
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 if (size_t(iter.depth()) >= iter.json_iter().parser->max_depth()) { return DEPTH_ERROR; }
325 json_type t;
326 SIMDJSON_TRY(type().get(t));
327 switch (t) {
328 case json_type::array:
329 return (*this).get_array().for_each_at_path_with_wildcard(json_path, std::forward<Func>(callback));
331 return (*this).get_object().for_each_at_path_with_wildcard(json_path, std::forward<Func>(callback));
332 default:
334 }
335}
336
337} // namespace ondemand
338} // namespace SIMDJSON_IMPLEMENTATION
339} // namespace simdjson
340
341namespace simdjson {
342
343simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::simdjson_result(
344 SIMDJSON_IMPLEMENTATION::ondemand::value &&value
345) noexcept :
346 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::value>(
347 std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>(value)
348 )
349{
350}
351simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::simdjson_result(
352 error_code error
353) noexcept :
354 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::value>(error)
355{
356}
357simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::count_elements() & noexcept {
358 if (error()) { return error(); }
359 return first.count_elements();
360}
361simdjson_inline simdjson_result<size_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::count_fields() & noexcept {
362 if (error()) { return error(); }
363 return first.count_fields();
364}
365simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::at(size_t index) noexcept {
366 if (error()) { return error(); }
367 return first.at(index);
368}
369simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::begin() & noexcept {
370 if (error()) { return error(); }
371 return first.begin();
372}
373simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::end() & noexcept {
374 if (error()) { return error(); }
375 return {};
376}
377
379 if (error()) { return error(); }
380 return first.find_field(key);
381}
383 if (error()) { return error(); }
384 return first.find_field(key);
385}
386
388 if (error()) { return error(); }
389 return first.find_field_unordered(key);
390}
392 if (error()) { return error(); }
393 return first.find_field_unordered(key);
394}
395
396simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator[](std::string_view key) noexcept {
397 if (error()) { return error(); }
398 return first[key];
399}
400simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator[](const char *key) noexcept {
401 if (error()) { return error(); }
402 return first[key];
403}
404
405simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_array() noexcept {
406 if (error()) { return error(); }
407 return first.get_array();
408}
409simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_object() noexcept {
410 if (error()) { return error(); }
411 return first.get_object();
412}
413simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint64() noexcept {
414 if (error()) { return error(); }
415 return first.get_uint64();
416}
417simdjson_inline simdjson_result<uint64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint64_in_string() noexcept {
418 if (error()) { return error(); }
419 return first.get_uint64_in_string();
420}
421simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int64() noexcept {
422 if (error()) { return error(); }
423 return first.get_int64();
424}
425simdjson_inline simdjson_result<int64_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int64_in_string() noexcept {
426 if (error()) { return error(); }
427 return first.get_int64_in_string();
428}
429simdjson_inline simdjson_result<uint32_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint32() noexcept {
430 if (error()) { return error(); }
431 return first.get_uint32();
432}
433simdjson_inline simdjson_result<int32_t> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int32() noexcept {
434 if (error()) { return error(); }
435 return first.get_int32();
436}
437simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_double() noexcept {
438 if (error()) { return error(); }
439 return first.get_double();
440}
441simdjson_inline simdjson_result<double> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_double_in_string() noexcept {
442 if (error()) { return error(); }
443 return first.get_double_in_string();
444}
445simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_string(bool allow_replacement) noexcept {
446 if (error()) { return error(); }
447 return first.get_string(allow_replacement);
448}
449template <typename string_type>
450simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_string(string_type& receiver, bool allow_replacement) noexcept {
451 if (error()) { return error(); }
452 return first.get_string(receiver, allow_replacement);
453}
454simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_wobbly_string() noexcept {
455 if (error()) { return error(); }
456 return first.get_wobbly_string();
457}
458simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_raw_json_string() noexcept {
459 if (error()) { return error(); }
460 return first.get_raw_json_string();
461}
462simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_bool() noexcept {
463 if (error()) { return error(); }
464 return first.get_bool();
465}
466simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_null() noexcept {
467 if (error()) { return error(); }
468 return first.is_null();
469}
470
471template<> simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>(SIMDJSON_IMPLEMENTATION::ondemand::value &out) noexcept {
472 if (error()) { return error(); }
473 out = first;
474 return SUCCESS;
475}
476
477template<typename T> simdjson_inline simdjson_result<T> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get() noexcept {
478 if (error()) { return error(); }
479 return first.get<T>();
480}
481template<typename T> simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get(T &out) noexcept {
482 if (error()) { return error(); }
483 return first.get<T>(out);
484}
485
486template<> simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get<SIMDJSON_IMPLEMENTATION::ondemand::value>() noexcept {
487 if (error()) { return error(); }
488 return std::move(first);
489}
490
492 if (error()) { return error(); }
493 return first.type();
494}
496 if (error()) { return error(); }
497 return first.is_scalar();
498}
499simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_string() noexcept {
500 if (error()) { return error(); }
501 return first.is_string();
502}
503simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_negative() noexcept {
504 if (error()) { return error(); }
505 return first.is_negative();
506}
507simdjson_inline simdjson_result<bool> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_integer() noexcept {
508 if (error()) { return error(); }
509 return first.is_integer();
510}
511simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::number_type> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_number_type() noexcept {
512 if (error()) { return error(); }
513 return first.get_number_type();
514}
515simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::number> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_number() noexcept {
516 if (error()) { return error(); }
517 return first.get_number();
518}
519#if SIMDJSON_EXCEPTIONS
520template <class T>
521simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator T() noexcept(false) {
522 if (error()) { throw simdjson_error(error()); }
523 return first.get<T>();
524}
525simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::array() noexcept(false) {
526 if (error()) { throw simdjson_error(error()); }
527 return first;
528}
529simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::object() noexcept(false) {
530 if (error()) { throw simdjson_error(error()); }
531 return first;
532}
533simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator uint64_t() noexcept(false) {
534 if (error()) { throw simdjson_error(error()); }
535 return first;
536}
537simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator int64_t() noexcept(false) {
538 if (error()) { throw simdjson_error(error()); }
539 return first;
540}
541simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator double() noexcept(false) {
542 if (error()) { throw simdjson_error(error()); }
543 return first;
544}
545simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator std::string_view() noexcept(false) {
546 if (error()) { throw simdjson_error(error()); }
547 return first;
548}
549simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string() noexcept(false) {
550 if (error()) { throw simdjson_error(error()); }
551 return first;
552}
553simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator bool() noexcept(false) {
554 if (error()) { throw simdjson_error(error()); }
555 return first;
556}
557#endif
558
560 if (error()) { return error(); }
561 return first.raw_json_token();
562}
563
565 if (error()) { return error(); }
566 return first.raw_json();
567}
568
570 if (error()) { return error(); }
571 return first.current_location();
572}
573
575 if (error()) { return error(); }
576 return first.current_depth();
577}
578
580 std::string_view json_pointer) noexcept {
581 if (error()) {
582 return error();
583 }
584 return first.at_pointer(json_pointer);
585}
586
587simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::at_path(
588 std::string_view json_path) noexcept {
589 if (error()) {
590 return error();
591 }
592 return first.at_path(json_path);
593}
594
595#if SIMDJSON_SUPPORTS_CONCEPTS
596template <typename Func>
597 requires std::invocable<Func, SIMDJSON_IMPLEMENTATION::ondemand::value>
598#else
599template <typename Func>
600#endif
601inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::for_each_at_path_with_wildcard(
602 std::string_view json_path, Func&& callback) noexcept {
603 if (error()) {
604 return error();
605 }
606 return first.for_each_at_path_with_wildcard(json_path, std::forward<Func>(callback));
607}
608
609} // namespace simdjson
610
611#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
@ DEPTH_ERROR
Your document exceeds the user-specified depth limitation.
Definition error.h:24
@ 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