simdjson 4.6.3
Ridiculously Fast JSON
Loading...
Searching...
No Matches
element-inl.h
1#ifndef SIMDJSON_ELEMENT_INL_H
2#define SIMDJSON_ELEMENT_INL_H
3
4#include "simdjson/dom/base.h"
5#include "simdjson/dom/element.h"
6#include "simdjson/dom/document.h"
7#include "simdjson/dom/object.h"
8#include "simdjson/internal/tape_type.h"
9
10#include "simdjson/dom/object-inl.h"
11#include "simdjson/error-inl.h"
12#include "simdjson/jsonpathutil.h"
13
14#include <ostream>
15#include <limits>
16
17namespace simdjson {
18
19//
20// simdjson_result<dom::element> inline implementation
21//
22simdjson_inline simdjson_result<dom::element>::simdjson_result() noexcept
23 : internal::simdjson_result_base<dom::element>() {}
24simdjson_inline simdjson_result<dom::element>::simdjson_result(dom::element &&value) noexcept
25 : internal::simdjson_result_base<dom::element>(std::forward<dom::element>(value)) {}
26simdjson_inline simdjson_result<dom::element>::simdjson_result(error_code error) noexcept
27 : internal::simdjson_result_base<dom::element>(error) {}
28inline simdjson_result<dom::element_type> simdjson_result<dom::element>::type() const noexcept {
29 if (error()) { return error(); }
30 return first.type();
31}
32
33template<typename T>
34simdjson_inline bool simdjson_result<dom::element>::is() const noexcept {
35 return !error() && first.is<T>();
36}
37template<typename T>
38simdjson_inline simdjson_result<T> simdjson_result<dom::element>::get() const noexcept {
39 if (error()) { return error(); }
40 return first.get<T>();
41}
42template<typename T>
43simdjson_warn_unused simdjson_inline error_code simdjson_result<dom::element>::get(T &value) const noexcept {
44 if (error()) { return error(); }
45 return first.get<T>(value);
46}
47
48simdjson_inline simdjson_result<dom::array> simdjson_result<dom::element>::get_array() const noexcept {
49 if (error()) { return error(); }
50 return first.get_array();
51}
52simdjson_inline simdjson_result<dom::object> simdjson_result<dom::element>::get_object() const noexcept {
53 if (error()) { return error(); }
54 return first.get_object();
55}
56simdjson_inline simdjson_result<const char *> simdjson_result<dom::element>::get_c_str() const noexcept {
57 if (error()) { return error(); }
58 return first.get_c_str();
59}
60simdjson_inline simdjson_result<size_t> simdjson_result<dom::element>::get_string_length() const noexcept {
61 if (error()) { return error(); }
62 return first.get_string_length();
63}
64simdjson_inline simdjson_result<std::string_view> simdjson_result<dom::element>::get_string() const noexcept {
65 if (error()) { return error(); }
66 return first.get_string();
67}
68simdjson_inline simdjson_result<int64_t> simdjson_result<dom::element>::get_int64() const noexcept {
69 if (error()) { return error(); }
70 return first.get_int64();
71}
72simdjson_inline simdjson_result<uint64_t> simdjson_result<dom::element>::get_uint64() const noexcept {
73 if (error()) { return error(); }
74 return first.get_uint64();
75}
76simdjson_inline simdjson_result<double> simdjson_result<dom::element>::get_double() const noexcept {
77 if (error()) { return error(); }
78 return first.get_double();
79}
80simdjson_inline simdjson_result<bool> simdjson_result<dom::element>::get_bool() const noexcept {
81 if (error()) { return error(); }
82 return first.get_bool();
83}
84simdjson_inline simdjson_result<std::string_view> simdjson_result<dom::element>::get_bigint() const noexcept {
85 if (error()) { return error(); }
86 return first.get_bigint();
87}
88
89simdjson_inline bool simdjson_result<dom::element>::is_array() const noexcept {
90 return !error() && first.is_array();
91}
92simdjson_inline bool simdjson_result<dom::element>::is_object() const noexcept {
93 return !error() && first.is_object();
94}
95simdjson_inline bool simdjson_result<dom::element>::is_string() const noexcept {
96 return !error() && first.is_string();
97}
98simdjson_inline bool simdjson_result<dom::element>::is_int64() const noexcept {
99 return !error() && first.is_int64();
100}
101simdjson_inline bool simdjson_result<dom::element>::is_uint64() const noexcept {
102 return !error() && first.is_uint64();
103}
104simdjson_inline bool simdjson_result<dom::element>::is_double() const noexcept {
105 return !error() && first.is_double();
106}
107simdjson_inline bool simdjson_result<dom::element>::is_number() const noexcept {
108 return !error() && first.is_number();
109}
110simdjson_inline bool simdjson_result<dom::element>::is_bool() const noexcept {
111 return !error() && first.is_bool();
112}
113
114simdjson_inline bool simdjson_result<dom::element>::is_null() const noexcept {
115 return !error() && first.is_null();
116}
117simdjson_inline bool simdjson_result<dom::element>::is_bigint() const noexcept {
118 return !error() && first.is_bigint();
119}
120
121simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::operator[](std::string_view key) const noexcept {
122 if (error()) { return error(); }
123 return first[key];
124}
125simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::operator[](const char *key) const noexcept {
126 if (error()) { return error(); }
127 return first[key];
128}
129simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at_pointer(const std::string_view json_pointer) const noexcept {
130 if (error()) { return error(); }
131 return first.at_pointer(json_pointer);
132}
133simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at_path(const std::string_view json_path) const noexcept {
134 auto json_pointer = json_path_to_pointer_conversion(json_path);
135 if (json_pointer == "-1") { return INVALID_JSON_POINTER; }
136 return at_pointer(json_pointer);
137}
138
139simdjson_inline simdjson_result<std::vector<dom::element>> simdjson_result<dom::element>::at_path_with_wildcard(const std::string_view json_path) const noexcept {
140 if (error()) { return error(); }
141 return first.at_path_with_wildcard(json_path);
142}
143
144#ifndef SIMDJSON_DISABLE_DEPRECATED_API
145[[deprecated("For standard compliance, use at_pointer instead, and prefix your pointers with a slash '/', see RFC6901 ")]]
146simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at(const std::string_view json_pointer) const noexcept {
147SIMDJSON_PUSH_DISABLE_WARNINGS
148SIMDJSON_DISABLE_DEPRECATED_WARNING
149 if (error()) { return error(); }
150 return first.at(json_pointer);
151SIMDJSON_POP_DISABLE_WARNINGS
152}
153#endif // SIMDJSON_DISABLE_DEPRECATED_API
154simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at(size_t index) const noexcept {
155 if (error()) { return error(); }
156 return first.at(index);
157}
158simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at_key(std::string_view key) const noexcept {
159 if (error()) { return error(); }
160 return first.at_key(key);
161}
162simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at_key_case_insensitive(std::string_view key) const noexcept {
163 if (error()) { return error(); }
164 return first.at_key_case_insensitive(key);
165}
166
167#if SIMDJSON_EXCEPTIONS
168
169simdjson_inline simdjson_result<dom::element>::operator bool() const noexcept(false) {
170 return get<bool>();
171}
172simdjson_inline simdjson_result<dom::element>::operator const char *() const noexcept(false) {
173 return get<const char *>();
174}
175simdjson_inline simdjson_result<dom::element>::operator std::string_view() const noexcept(false) {
176 return get<std::string_view>();
177}
178simdjson_inline simdjson_result<dom::element>::operator uint64_t() const noexcept(false) {
179 return get<uint64_t>();
180}
181simdjson_inline simdjson_result<dom::element>::operator int64_t() const noexcept(false) {
182 return get<int64_t>();
183}
184simdjson_inline simdjson_result<dom::element>::operator double() const noexcept(false) {
185 return get<double>();
186}
187simdjson_inline simdjson_result<dom::element>::operator dom::array() const noexcept(false) {
188 return get<dom::array>();
189}
190simdjson_inline simdjson_result<dom::element>::operator dom::object() const noexcept(false) {
191 return get<dom::object>();
192}
193
194simdjson_inline dom::array::iterator simdjson_result<dom::element>::begin() const noexcept(false) {
195 if (error()) { throw simdjson_error(error()); }
196 return first.begin();
197}
198simdjson_inline dom::array::iterator simdjson_result<dom::element>::end() const noexcept(false) {
199 if (error()) { throw simdjson_error(error()); }
200 return first.end();
201}
202
203#endif // SIMDJSON_EXCEPTIONS
204
205namespace dom {
206
207//
208// element inline implementation
209//
210simdjson_inline element::element() noexcept : tape{} {}
211simdjson_inline element::element(const internal::tape_ref &_tape) noexcept : tape{_tape} { }
212
213inline element_type element::type() const noexcept {
214 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
215 auto tape_type = tape.tape_ref_type();
216 return tape_type == internal::tape_type::FALSE_VALUE ? element_type::BOOL : static_cast<element_type>(tape_type);
217}
218
220 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
221 if(tape.is_true()) {
222 return true;
223 } else if(tape.is_false()) {
224 return false;
225 }
226 return INCORRECT_TYPE;
227}
229 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable());
230 switch (tape.tape_ref_type()) {
231 case internal::tape_type::BIGINT:
232 return tape.get_string_view();
233 default:
234 return INCORRECT_TYPE;
235 }
236}
238 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
239 switch (tape.tape_ref_type()) {
240 case internal::tape_type::STRING: {
241 return tape.get_c_str();
242 }
243 default:
244 return INCORRECT_TYPE;
245 }
246}
248 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
249 switch (tape.tape_ref_type()) {
250 case internal::tape_type::STRING: {
251 return tape.get_string_length();
252 }
253 default:
254 return INCORRECT_TYPE;
255 }
256}
258 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
259 switch (tape.tape_ref_type()) {
260 case internal::tape_type::STRING:
261 return tape.get_string_view();
262 default:
263 return INCORRECT_TYPE;
264 }
265}
267 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
268 if(simdjson_unlikely(!tape.is_uint64())) { // branch rarely taken
269 if(tape.is_int64()) {
270 int64_t result = tape.next_tape_value<int64_t>();
271 if (result < 0) {
272 return NUMBER_OUT_OF_RANGE;
273 }
274 return uint64_t(result);
275 }
276 return INCORRECT_TYPE;
277 }
278 return tape.next_tape_value<int64_t>();
279}
281 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
282 if(simdjson_unlikely(!tape.is_int64())) { // branch rarely taken
283 if(tape.is_uint64()) {
284 uint64_t result = tape.next_tape_value<uint64_t>();
285 // Wrapping max in parens to handle Windows issue: https://stackoverflow.com/questions/11544073/how-do-i-deal-with-the-max-macro-in-windows-h-colliding-with-max-in-std
286 if (result > uint64_t((std::numeric_limits<int64_t>::max)())) {
287 return NUMBER_OUT_OF_RANGE;
288 }
289 return static_cast<int64_t>(result);
290 }
291 return INCORRECT_TYPE;
292 }
293 return tape.next_tape_value<int64_t>();
294}
296 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
297 // Performance considerations:
298 // 1. Querying tape_ref_type() implies doing a shift, it is fast to just do a straight
299 // comparison.
300 // 2. Using a switch-case relies on the compiler guessing what kind of code generation
301 // we want... But the compiler cannot know that we expect the type to be "double"
302 // most of the time.
303 // We can expect get<double> to refer to a double type almost all the time.
304 // It is important to craft the code accordingly so that the compiler can use this
305 // information. (This could also be solved with profile-guided optimization.)
306 if(simdjson_unlikely(!tape.is_double())) { // branch rarely taken
307 if(tape.is_uint64()) {
308 return double(tape.next_tape_value<uint64_t>());
309 } else if(tape.is_int64()) {
310 return double(tape.next_tape_value<int64_t>());
311 }
312 return INCORRECT_TYPE;
313 }
314 // this is common:
315 return tape.next_tape_value<double>();
316}
318 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
319 switch (tape.tape_ref_type()) {
320 case internal::tape_type::START_ARRAY:
321 return array(tape);
322 default:
323 return INCORRECT_TYPE;
324 }
325}
327 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
328 switch (tape.tape_ref_type()) {
329 case internal::tape_type::START_OBJECT:
330 return object(tape);
331 default:
332 return INCORRECT_TYPE;
333 }
334}
335
336template<typename T>
337simdjson_warn_unused simdjson_inline error_code element::get(T &value) const noexcept {
338 return get<T>().get(value);
339}
340// An element-specific version prevents recursion with simdjson_result::get<element>(value)
341template<>
342simdjson_warn_unused simdjson_inline error_code element::get<element>(element &value) const noexcept {
343 value = element(tape);
344 return SUCCESS;
345}
346template<typename T>
347inline void element::tie(T &value, error_code &error) && noexcept {
348 error = get<T>(value);
349}
350
351template<typename T>
352simdjson_inline bool element::is() const noexcept {
353 auto result = get<T>();
354 return !result.error();
355}
356
357template<> inline simdjson_result<array> element::get<array>() const noexcept { return get_array(); }
358template<> inline simdjson_result<object> element::get<object>() const noexcept { return get_object(); }
359template<> inline simdjson_result<const char *> element::get<const char *>() const noexcept { return get_c_str(); }
360template<> inline simdjson_result<std::string_view> element::get<std::string_view>() const noexcept { return get_string(); }
361template<> inline simdjson_result<int64_t> element::get<int64_t>() const noexcept { return get_int64(); }
362template<> inline simdjson_result<uint64_t> element::get<uint64_t>() const noexcept { return get_uint64(); }
363template<> inline simdjson_result<double> element::get<double>() const noexcept { return get_double(); }
364template<> inline simdjson_result<bool> element::get<bool>() const noexcept { return get_bool(); }
365
366inline bool element::is_array() const noexcept { return is<array>(); }
367inline bool element::is_object() const noexcept { return is<object>(); }
368inline bool element::is_string() const noexcept { return is<std::string_view>(); }
369inline bool element::is_int64() const noexcept { return is<int64_t>(); }
370inline bool element::is_uint64() const noexcept { return is<uint64_t>(); }
371inline bool element::is_double() const noexcept { return is<double>(); }
372inline bool element::is_bool() const noexcept { return is<bool>(); }
373inline bool element::is_number() const noexcept { return is_int64() || is_uint64() || is_double(); }
374
375inline bool element::is_null() const noexcept {
376 return tape.is_null_on_tape();
377}
378
379inline bool element::is_bigint() const noexcept {
380 return tape.tape_ref_type() == internal::tape_type::BIGINT;
381}
382
383#if SIMDJSON_EXCEPTIONS
384
385inline element::operator bool() const noexcept(false) { return get<bool>(); }
386inline element::operator const char*() const noexcept(false) { return get<const char *>(); }
387inline element::operator std::string_view() const noexcept(false) { return get<std::string_view>(); }
388inline element::operator uint64_t() const noexcept(false) { return get<uint64_t>(); }
389inline element::operator int64_t() const noexcept(false) { return get<int64_t>(); }
390inline element::operator double() const noexcept(false) { return get<double>(); }
391inline element::operator array() const noexcept(false) { return get<array>(); }
392inline element::operator object() const noexcept(false) { return get<object>(); }
393
394inline array::iterator element::begin() const noexcept(false) {
395 return get<array>().begin();
396}
397inline array::iterator element::end() const noexcept(false) {
398 return get<array>().end();
399}
400
401#endif // SIMDJSON_EXCEPTIONS
402
403inline simdjson_result<element> element::operator[](std::string_view key) const noexcept {
404 return at_key(key);
405}
406inline simdjson_result<element> element::operator[](const char *key) const noexcept {
407 return at_key(key);
408}
409
410inline bool is_pointer_well_formed(std::string_view json_pointer) noexcept {
411 if (simdjson_unlikely(json_pointer[0] != '/')) {
412 return false;
413 }
414 size_t escape = json_pointer.find('~');
415 if (escape == std::string_view::npos) {
416 return true;
417 }
418 if (escape == json_pointer.size() - 1) {
419 return false;
420 }
421 if (json_pointer[escape + 1] != '0' && json_pointer[escape + 1] != '1') {
422 return false;
423 }
424 return true;
425}
426
427inline simdjson_result<element> element::at_pointer(std::string_view json_pointer) const noexcept {
428 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
429 switch (tape.tape_ref_type()) {
430 case internal::tape_type::START_OBJECT:
431 return object(tape).at_pointer(json_pointer);
432 case internal::tape_type::START_ARRAY:
433 return array(tape).at_pointer(json_pointer);
434 default: {
435 if (!json_pointer.empty()) { // a non-empty string can be invalid, or accessing a primitive (issue 2154)
436 if (is_pointer_well_formed(json_pointer)) {
437 return NO_SUCH_FIELD;
438 }
440 }
441 // an empty string means that we return the current node
442 dom::element copy(*this);
443 return simdjson_result<element>(std::move(copy));
444 }
445 }
446}
447
448inline simdjson_result<std::vector<element>> element::at_path_with_wildcard(std::string_view json_path) const noexcept {
449 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
450
451 switch (tape.tape_ref_type()) {
452 case internal::tape_type::START_OBJECT:
453 return object(tape).at_path_with_wildcard(json_path);
454 case internal::tape_type::START_ARRAY:
455 return array(tape).at_path_with_wildcard(json_path);
456 default:
457 return std::vector<element>{};
458 }
459}
460
461inline simdjson_result<element> element::at_path(std::string_view json_path) const noexcept {
462 auto json_pointer = json_path_to_pointer_conversion(json_path);
463 if (json_pointer == "-1") { return INVALID_JSON_POINTER; }
464 return at_pointer(json_pointer);
465}
466#ifndef SIMDJSON_DISABLE_DEPRECATED_API
467[[deprecated("For standard compliance, use at_pointer instead, and prefix your pointers with a slash '/', see RFC6901 ")]]
468inline simdjson_result<element> element::at(std::string_view json_pointer) const noexcept {
469 // version 0.4 of simdjson allowed non-compliant pointers
470 auto std_pointer = (json_pointer.empty() ? "" : "/") + std::string(json_pointer.begin(), json_pointer.end());
471 return at_pointer(std_pointer);
472}
473#endif // SIMDJSON_DISABLE_DEPRECATED_API
474
475inline simdjson_result<element> element::at(size_t index) const noexcept {
476 return get<array>().at(index);
477}
478inline simdjson_result<element> element::at_key(std::string_view key) const noexcept {
479 return get<object>().at_key(key);
480}
481inline simdjson_result<element> element::at_key_case_insensitive(std::string_view key) const noexcept {
482 return get<object>().at_key_case_insensitive(key);
483}
484inline bool element::operator<(const element &other) const noexcept {
485 return tape.json_index < other.tape.json_index;
486}
487inline bool element::operator==(const element &other) const noexcept {
488 return tape.json_index == other.tape.json_index;
489}
490
491inline bool element::dump_raw_tape(std::ostream &out) const noexcept {
492 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
493 return tape.doc->dump_raw_tape(out);
494}
495
496
497inline std::ostream& operator<<(std::ostream& out, element_type type) {
498 switch (type) {
500 return out << "array";
502 return out << "object";
504 return out << "int64_t";
506 return out << "uint64_t";
508 return out << "double";
510 return out << "string";
512 return out << "bool";
514 return out << "null";
516 return out << "bigint";
517 default:
518 return out << "unexpected content!!!"; // abort() usage is forbidden in the library
519 }
520}
521
522} // namespace dom
523
524} // namespace simdjson
525
526#endif // SIMDJSON_ELEMENT_INL_H
JSON array.
Definition array.h:15
simdjson_result< std::vector< element > > at_path_with_wildcard(std::string_view json_path) const noexcept
Adds support for JSONPath expression with wildcards '*'.
Definition array-inl.h:162
simdjson_result< element > at_pointer(std::string_view json_pointer) const noexcept
Get the value associated with the given JSON pointer.
Definition array-inl.h:94
A JSON element.
Definition element.h:34
bool is_object() const noexcept
Whether this element is a json object.
bool is_double() const noexcept
Whether this element is a json number that fits in a double.
simdjson_inline element_type type() const noexcept
The type of this element.
bool is_number() const noexcept
Whether this element is a json number.
simdjson_result< T > get() const noexcept
Get the value as the provided type (T).
Definition element.h:227
simdjson_result< const char * > get_c_str() const noexcept
Cast this element to a null-terminated C string.
bool operator<(const element &other) const noexcept
operator< defines a total order for element allowing to use them in ordered C++ STL containers
simdjson_result< element > at_pointer(const std::string_view json_pointer) const noexcept
Get the value associated with the given JSON pointer.
simdjson_result< double > get_double() const noexcept
Cast this element to a double floating-point.
simdjson_inline bool is() const noexcept
Tell whether the value can be cast to provided type (T).
simdjson_result< element > at_key_case_insensitive(std::string_view key) const noexcept
Get the value associated with the given key in a case-insensitive manner.
void tie(T &value, error_code &error) &&noexcept
Get the value as the provided type (T), setting error if it's not the given type.
simdjson_result< bool > get_bool() const noexcept
Cast this element to a bool.
bool is_string() const noexcept
Whether this element is a json string.
simdjson_result< element > at_key(std::string_view key) const noexcept
Get the value associated with the given key.
simdjson_result< std::string_view > get_bigint() const noexcept
Read this element as a big integer (raw digit string).
dom::array::iterator end() const noexcept(false)
Iterate over each element in this array.
simdjson_result< array > get_array() const noexcept
Cast this element to an array.
simdjson_result< size_t > get_string_length() const noexcept
Gives the length in bytes of the string.
simdjson_inline element() noexcept
Create a new, invalid element.
simdjson_result< uint64_t > get_uint64() const noexcept
Cast this element to an unsigned integer.
dom::array::iterator begin() const noexcept(false)
Iterate over each element in this array.
simdjson_result< element > at(const std::string_view json_pointer) const noexcept
Version 0.4 of simdjson used an incorrect interpretation of the JSON Pointer standard and allowed the...
simdjson_result< int64_t > get_int64() const noexcept
Cast this element to a signed integer.
bool is_bigint() const noexcept
Whether this element is a big integer (number exceeding 64-bit range).
simdjson_result< object > get_object() const noexcept
Cast this element to an object.
bool is_uint64() const noexcept
Whether this element is a json number that fits in an unsigned 64-bit integer.
simdjson_result< element > operator[](std::string_view key) const noexcept
Get the value associated with the given key.
bool is_int64() const noexcept
Whether this element is a json number that fits in a signed 64-bit integer.
bool is_null() const noexcept
Whether this element is a json null.
simdjson_result< element > at_path(std::string_view json_path) const noexcept
Get the value associated with the given JSONPath expression.
simdjson_result< std::string_view > get_string() const noexcept
Cast this element to a string.
bool is_array() const noexcept
Whether this element is a json array.
bool operator==(const element &other) const noexcept
operator== allows to verify if two element values reference the same JSON item
bool is_bool() const noexcept
Whether this element is a json true or false.
JSON object.
Definition object.h:16
simdjson_result< std::vector< element > > at_path_with_wildcard(std::string_view json_path) const noexcept
Adds support for JSONPath expression with wildcards '*'.
Definition object-inl.h:175
simdjson_result< element > at_pointer(std::string_view json_pointer) const noexcept
Get the value associated with the given JSON pointer.
Definition object-inl.h:104
element_type
The actual concrete type of a JSON element This is the type it is most easily cast to with get<>.
Definition element.h:16
@ STRING
std::string_view
@ UINT64
uint64_t: any integer that fits in uint64_t but not int64_t
@ BIGINT
std::string_view: big integer stored as raw digit string
@ DOUBLE
double: Any number with a "." or "e" that fits in double.
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
@ INCORRECT_TYPE
JSON element has a different type than user expected.
Definition error.h:37
@ 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
std::string json_path_to_pointer_conversion(std::string_view json_path)
Converts JSONPath to JSON Pointer.
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