simdjson 5.0.2
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}
68#if SIMDJSON_SUPPORTS_CHAR8_T
69simdjson_inline simdjson_result<std::u8string_view> simdjson_result<dom::element>::get_u8string() const noexcept {
70 if (error()) { return error(); }
71 return first.get_u8string();
72}
73#endif
74simdjson_inline simdjson_result<int64_t> simdjson_result<dom::element>::get_int64() const noexcept {
75 if (error()) { return error(); }
76 return first.get_int64();
77}
78simdjson_inline simdjson_result<uint64_t> simdjson_result<dom::element>::get_uint64() const noexcept {
79 if (error()) { return error(); }
80 return first.get_uint64();
81}
82simdjson_inline simdjson_result<double> simdjson_result<dom::element>::get_double() const noexcept {
83 if (error()) { return error(); }
84 return first.get_double();
85}
86simdjson_inline simdjson_result<bool> simdjson_result<dom::element>::get_bool() const noexcept {
87 if (error()) { return error(); }
88 return first.get_bool();
89}
90simdjson_inline simdjson_result<std::string_view> simdjson_result<dom::element>::get_bigint() const noexcept {
91 if (error()) { return error(); }
92 return first.get_bigint();
93}
94
95simdjson_inline bool simdjson_result<dom::element>::is_array() const noexcept {
96 return !error() && first.is_array();
97}
98simdjson_inline bool simdjson_result<dom::element>::is_object() const noexcept {
99 return !error() && first.is_object();
100}
101simdjson_inline bool simdjson_result<dom::element>::is_string() const noexcept {
102 return !error() && first.is_string();
103}
104simdjson_inline bool simdjson_result<dom::element>::is_int64() const noexcept {
105 return !error() && first.is_int64();
106}
107simdjson_inline bool simdjson_result<dom::element>::is_uint64() const noexcept {
108 return !error() && first.is_uint64();
109}
110simdjson_inline bool simdjson_result<dom::element>::is_double() const noexcept {
111 return !error() && first.is_double();
112}
113simdjson_inline bool simdjson_result<dom::element>::is_number() const noexcept {
114 return !error() && first.is_number();
115}
116simdjson_inline bool simdjson_result<dom::element>::is_bool() const noexcept {
117 return !error() && first.is_bool();
118}
119
120simdjson_inline bool simdjson_result<dom::element>::is_null() const noexcept {
121 return !error() && first.is_null();
122}
123simdjson_inline bool simdjson_result<dom::element>::is_bigint() const noexcept {
124 return !error() && first.is_bigint();
125}
126
127simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::operator[](std::string_view key) const noexcept {
128 if (error()) { return error(); }
129 return first[key];
130}
131simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::operator[](const char *key) const noexcept {
132 if (error()) { return error(); }
133 return first[key];
134}
135simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at_pointer(const std::string_view json_pointer) const noexcept {
136 if (error()) { return error(); }
137 return first.at_pointer(json_pointer);
138}
139simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at_path(const std::string_view json_path) const noexcept {
140 if (error()) { return error(); }
141 auto json_pointer = json_path_to_pointer_conversion(json_path);
142 if (json_pointer == "-1") { return INVALID_JSON_POINTER; }
143 return at_pointer(json_pointer);
144}
145
146simdjson_inline simdjson_result<std::vector<dom::element>> simdjson_result<dom::element>::at_path_with_wildcard(const std::string_view json_path) const noexcept {
147 if (error()) { return error(); }
148 return first.at_path_with_wildcard(json_path);
149}
150
151#ifndef SIMDJSON_DISABLE_DEPRECATED_API
152[[deprecated("For standard compliance, use at_pointer instead, and prefix your pointers with a slash '/', see RFC6901 ")]]
153simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at(const std::string_view json_pointer) const noexcept {
154SIMDJSON_PUSH_DISABLE_WARNINGS
155SIMDJSON_DISABLE_DEPRECATED_WARNING
156 if (error()) { return error(); }
157 return first.at(json_pointer);
158SIMDJSON_POP_DISABLE_WARNINGS
159}
160#endif // SIMDJSON_DISABLE_DEPRECATED_API
161simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at(size_t index) const noexcept {
162 if (error()) { return error(); }
163 return first.at(index);
164}
165simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at_key(std::string_view key) const noexcept {
166 if (error()) { return error(); }
167 return first.at_key(key);
168}
169simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at_key_case_insensitive(std::string_view key) const noexcept {
170 if (error()) { return error(); }
171 return first.at_key_case_insensitive(key);
172}
173
174#if SIMDJSON_EXCEPTIONS
175
176simdjson_inline simdjson_result<dom::element>::operator bool() const noexcept(false) {
177 return get<bool>();
178}
179simdjson_inline simdjson_result<dom::element>::operator const char *() const noexcept(false) {
180 return get<const char *>();
181}
182simdjson_inline simdjson_result<dom::element>::operator std::string_view() const noexcept(false) {
183 return get<std::string_view>();
184}
185simdjson_inline simdjson_result<dom::element>::operator uint64_t() const noexcept(false) {
186 return get<uint64_t>();
187}
188simdjson_inline simdjson_result<dom::element>::operator int64_t() const noexcept(false) {
189 return get<int64_t>();
190}
191simdjson_inline simdjson_result<dom::element>::operator double() const noexcept(false) {
192 return get<double>();
193}
194simdjson_inline simdjson_result<dom::element>::operator dom::array() const noexcept(false) {
195 return get<dom::array>();
196}
197simdjson_inline simdjson_result<dom::element>::operator dom::object() const noexcept(false) {
198 return get<dom::object>();
199}
200
201simdjson_inline dom::array::iterator simdjson_result<dom::element>::begin() const noexcept(false) {
202 if (error()) { throw simdjson_error(error()); }
203 return first.begin();
204}
205simdjson_inline dom::array::iterator simdjson_result<dom::element>::end() const noexcept(false) {
206 if (error()) { throw simdjson_error(error()); }
207 return first.end();
208}
209
210#endif // SIMDJSON_EXCEPTIONS
211
212namespace dom {
213
214//
215// element inline implementation
216//
217simdjson_inline element::element() noexcept : tape{} {}
218simdjson_inline element::element(const internal::tape_ref &_tape) noexcept : tape{_tape} { }
219
220inline element_type element::type() const noexcept {
221 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
222 auto tape_type = tape.tape_ref_type();
223 return tape_type == internal::tape_type::FALSE_VALUE ? element_type::BOOL : static_cast<element_type>(tape_type);
224}
225
227 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
228 if(tape.is_true()) {
229 return true;
230 } else if(tape.is_false()) {
231 return false;
232 }
233 return INCORRECT_TYPE;
234}
236 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable());
237 switch (tape.tape_ref_type()) {
238 case internal::tape_type::BIGINT:
239 return tape.get_string_view();
240 default:
241 return INCORRECT_TYPE;
242 }
243}
245 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
246 switch (tape.tape_ref_type()) {
247 case internal::tape_type::STRING: {
248 return tape.get_c_str();
249 }
250 default:
251 return INCORRECT_TYPE;
252 }
253}
255 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
256 switch (tape.tape_ref_type()) {
257 case internal::tape_type::STRING: {
258 return tape.get_string_length();
259 }
260 default:
261 return INCORRECT_TYPE;
262 }
263}
265 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
266 switch (tape.tape_ref_type()) {
267 case internal::tape_type::STRING:
268 return tape.get_string_view();
269 default:
270 return INCORRECT_TYPE;
271 }
272}
273#if SIMDJSON_SUPPORTS_CHAR8_T
274inline simdjson_result<std::u8string_view> element::get_u8string() const noexcept {
275 std::string_view v;
276 SIMDJSON_TRY(get_string().get(v));
277 return internal::as_u8string_view(v);
278}
279#endif
281 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
282 if(simdjson_unlikely(!tape.is_uint64())) { // branch rarely taken
283 if(tape.is_int64()) {
284 int64_t result = tape.next_tape_value<int64_t>();
285 if (result < 0) {
286 return NUMBER_OUT_OF_RANGE;
287 }
288 return uint64_t(result);
289 }
290 return INCORRECT_TYPE;
291 }
292 return tape.next_tape_value<int64_t>();
293}
295 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
296 if(simdjson_unlikely(!tape.is_int64())) { // branch rarely taken
297 if(tape.is_uint64()) {
298 uint64_t result = tape.next_tape_value<uint64_t>();
299 // 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
300 if (result > uint64_t((std::numeric_limits<int64_t>::max)())) {
301 return NUMBER_OUT_OF_RANGE;
302 }
303 return static_cast<int64_t>(result);
304 }
305 return INCORRECT_TYPE;
306 }
307 return tape.next_tape_value<int64_t>();
308}
310 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
311 // Performance considerations:
312 // 1. Querying tape_ref_type() implies doing a shift, it is fast to just do a straight
313 // comparison.
314 // 2. Using a switch-case relies on the compiler guessing what kind of code generation
315 // we want... But the compiler cannot know that we expect the type to be "double"
316 // most of the time.
317 // We can expect get<double> to refer to a double type almost all the time.
318 // It is important to craft the code accordingly so that the compiler can use this
319 // information. (This could also be solved with profile-guided optimization.)
320 if(simdjson_unlikely(!tape.is_double())) { // branch rarely taken
321 if(tape.is_uint64()) {
322 return double(tape.next_tape_value<uint64_t>());
323 } else if(tape.is_int64()) {
324 return double(tape.next_tape_value<int64_t>());
325 }
326 return INCORRECT_TYPE;
327 }
328 // this is common:
329 return tape.next_tape_value<double>();
330}
332 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
333 switch (tape.tape_ref_type()) {
334 case internal::tape_type::START_ARRAY:
335 return array(tape);
336 default:
337 return INCORRECT_TYPE;
338 }
339}
341 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
342 switch (tape.tape_ref_type()) {
343 case internal::tape_type::START_OBJECT:
344 return object(tape);
345 default:
346 return INCORRECT_TYPE;
347 }
348}
349
350template<typename T>
351simdjson_warn_unused simdjson_inline error_code element::get(T &value) const noexcept {
352 return get<T>().get(value);
353}
354// An element-specific version prevents recursion with simdjson_result::get<element>(value)
355template<>
356simdjson_warn_unused simdjson_inline error_code element::get<element>(element &value) const noexcept {
357 value = element(tape);
358 return SUCCESS;
359}
360template<typename T>
361inline void element::tie(T &value, error_code &error) && noexcept {
362 error = get<T>(value);
363}
364
365template<typename T>
366simdjson_inline bool element::is() const noexcept {
367 auto result = get<T>();
368 return !result.error();
369}
370
371template<> inline simdjson_result<array> element::get<array>() const noexcept { return get_array(); }
372template<> inline simdjson_result<object> element::get<object>() const noexcept { return get_object(); }
373template<> inline simdjson_result<const char *> element::get<const char *>() const noexcept { return get_c_str(); }
374template<> inline simdjson_result<std::string_view> element::get<std::string_view>() const noexcept { return get_string(); }
375#if SIMDJSON_SUPPORTS_CHAR8_T
376template<> inline simdjson_result<std::u8string_view> element::get<std::u8string_view>() const noexcept { return get_u8string(); }
377#endif
378template<> inline simdjson_result<int64_t> element::get<int64_t>() const noexcept { return get_int64(); }
379template<> inline simdjson_result<uint64_t> element::get<uint64_t>() const noexcept { return get_uint64(); }
380template<> inline simdjson_result<double> element::get<double>() const noexcept { return get_double(); }
381template<> inline simdjson_result<bool> element::get<bool>() const noexcept { return get_bool(); }
382
383inline bool element::is_array() const noexcept { return is<array>(); }
384inline bool element::is_object() const noexcept { return is<object>(); }
385inline bool element::is_string() const noexcept { return is<std::string_view>(); }
386inline bool element::is_int64() const noexcept { return is<int64_t>(); }
387inline bool element::is_uint64() const noexcept { return is<uint64_t>(); }
388inline bool element::is_double() const noexcept { return is<double>(); }
389inline bool element::is_bool() const noexcept { return is<bool>(); }
390inline bool element::is_number() const noexcept { return is_int64() || is_uint64() || is_double(); }
391
392inline bool element::is_null() const noexcept {
393 return tape.is_null_on_tape();
394}
395
396inline bool element::is_bigint() const noexcept {
397 return tape.tape_ref_type() == internal::tape_type::BIGINT;
398}
399
400#if SIMDJSON_EXCEPTIONS
401
402inline element::operator bool() const noexcept(false) { return get<bool>(); }
403inline element::operator const char*() const noexcept(false) { return get<const char *>(); }
404inline element::operator std::string_view() const noexcept(false) { return get<std::string_view>(); }
405inline element::operator uint64_t() const noexcept(false) { return get<uint64_t>(); }
406inline element::operator int64_t() const noexcept(false) { return get<int64_t>(); }
407inline element::operator double() const noexcept(false) { return get<double>(); }
408inline element::operator array() const noexcept(false) { return get<array>(); }
409inline element::operator object() const noexcept(false) { return get<object>(); }
410
411inline array::iterator element::begin() const noexcept(false) {
412 return get<array>().begin();
413}
414inline array::iterator element::end() const noexcept(false) {
415 return get<array>().end();
416}
417
418#endif // SIMDJSON_EXCEPTIONS
419
420inline simdjson_result<element> element::operator[](std::string_view key) const noexcept {
421 return at_key(key);
422}
423inline simdjson_result<element> element::operator[](const char *key) const noexcept {
424 return at_key(key);
425}
426
427inline bool is_pointer_well_formed(std::string_view json_pointer) noexcept {
428 if (simdjson_unlikely(json_pointer[0] != '/')) {
429 return false;
430 }
431 size_t escape = json_pointer.find('~');
432 if (escape == std::string_view::npos) {
433 return true;
434 }
435 if (escape == json_pointer.size() - 1) {
436 return false;
437 }
438 if (json_pointer[escape + 1] != '0' && json_pointer[escape + 1] != '1') {
439 return false;
440 }
441 return true;
442}
443
444inline simdjson_result<element> element::at_pointer(std::string_view json_pointer) const noexcept {
445 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
446 switch (tape.tape_ref_type()) {
447 case internal::tape_type::START_OBJECT:
448 return object(tape).at_pointer(json_pointer);
449 case internal::tape_type::START_ARRAY:
450 return array(tape).at_pointer(json_pointer);
451 default: {
452 if (!json_pointer.empty()) { // a non-empty string can be invalid, or accessing a primitive (issue 2154)
453 if (is_pointer_well_formed(json_pointer)) {
454 return NO_SUCH_FIELD;
455 }
457 }
458 // an empty string means that we return the current node
459 dom::element copy(*this);
460 return simdjson_result<element>(std::move(copy));
461 }
462 }
463}
464
465inline simdjson_result<std::vector<element>> element::at_path_with_wildcard(std::string_view json_path) const noexcept {
466 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
467
468 switch (tape.tape_ref_type()) {
469 case internal::tape_type::START_OBJECT:
470 return object(tape).at_path_with_wildcard(json_path);
471 case internal::tape_type::START_ARRAY:
472 return array(tape).at_path_with_wildcard(json_path);
473 default:
474 return std::vector<element>{};
475 }
476}
477
478inline simdjson_result<element> element::at_path(std::string_view json_path) const noexcept {
479 auto json_pointer = json_path_to_pointer_conversion(json_path);
480 if (json_pointer == "-1") { return INVALID_JSON_POINTER; }
481 return at_pointer(json_pointer);
482}
483#ifndef SIMDJSON_DISABLE_DEPRECATED_API
484[[deprecated("For standard compliance, use at_pointer instead, and prefix your pointers with a slash '/', see RFC6901 ")]]
485inline simdjson_result<element> element::at(std::string_view json_pointer) const noexcept {
486 // version 0.4 of simdjson allowed non-compliant pointers
487 auto std_pointer = (json_pointer.empty() ? "" : "/") + std::string(json_pointer.begin(), json_pointer.end());
488 return at_pointer(std_pointer);
489}
490#endif // SIMDJSON_DISABLE_DEPRECATED_API
491
492inline simdjson_result<element> element::at(size_t index) const noexcept {
493 return get<array>().at(index);
494}
495inline simdjson_result<element> element::at_key(std::string_view key) const noexcept {
496 return get<object>().at_key(key);
497}
498inline simdjson_result<element> element::at_key_case_insensitive(std::string_view key) const noexcept {
499 return get<object>().at_key_case_insensitive(key);
500}
501inline bool element::operator<(const element &other) const noexcept {
502 return tape.json_index < other.tape.json_index;
503}
504inline bool element::operator==(const element &other) const noexcept {
505 return tape.json_index == other.tape.json_index;
506}
507
508inline bool element::dump_raw_tape(std::ostream &out) const noexcept {
509 SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
510 return tape.doc->dump_raw_tape(out);
511}
512
513
514inline std::ostream& operator<<(std::ostream& out, element_type type) {
515 switch (type) {
517 return out << "array";
519 return out << "object";
521 return out << "int64_t";
523 return out << "uint64_t";
525 return out << "double";
527 return out << "string";
529 return out << "bool";
531 return out << "null";
533 return out << "bigint";
534 default:
535 return out << "unexpected content!!!"; // abort() usage is forbidden in the library
536 }
537}
538
539} // namespace dom
540
541} // namespace simdjson
542
543#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:167
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:112
A JSON element.
Definition element.h:36
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:243
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:105
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
The BIGINT type is for integers that do not fit in 64 bits. It is only present.
@ 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:281
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.
Definition error-inl.h:163