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