![]() |
simdjson 4.2.1
Ridiculously Fast JSON
|
A JSON element. More...
#include <element.h>
Public Member Functions | |
| simdjson_inline | element () noexcept |
| Create a new, invalid element. | |
| simdjson_inline element_type | type () const noexcept |
| The type of this element. | |
| simdjson_result< array > | get_array () const noexcept |
| Cast this element to an array. | |
| simdjson_result< object > | get_object () const noexcept |
| Cast this element to an object. | |
| simdjson_result< const char * > | get_c_str () const noexcept |
| Cast this element to a null-terminated C string. | |
| simdjson_result< size_t > | get_string_length () const noexcept |
| Gives the length in bytes of the string. | |
| simdjson_result< std::string_view > | get_string () const noexcept |
| Cast this element to a string. | |
| simdjson_result< int64_t > | get_int64 () const noexcept |
| Cast this element to a signed integer. | |
| simdjson_result< uint64_t > | get_uint64 () const noexcept |
| Cast this element to an unsigned integer. | |
| simdjson_result< double > | get_double () const noexcept |
| Cast this element to a double floating-point. | |
| simdjson_result< bool > | get_bool () const noexcept |
| Cast this element to a bool. | |
| bool | is_array () const noexcept |
| Whether this element is a json array. | |
| bool | is_object () const noexcept |
| Whether this element is a json object. | |
| bool | is_string () const noexcept |
| Whether this element is a json string. | |
| bool | is_int64 () const noexcept |
| Whether this element is a json number that fits in a signed 64-bit integer. | |
| bool | is_uint64 () const noexcept |
| Whether this element is a json number that fits in an unsigned 64-bit integer. | |
| bool | is_double () const noexcept |
| Whether this element is a json number that fits in a double. | |
| bool | is_number () const noexcept |
| Whether this element is a json number. | |
| bool | is_bool () const noexcept |
Whether this element is a json true or false. | |
| bool | is_null () const noexcept |
Whether this element is a json null. | |
| template<typename T > | |
| simdjson_inline bool | is () const noexcept |
| Tell whether the value can be cast to provided type (T). | |
| template<typename T > | |
| simdjson_result< T > | get () const noexcept |
| Get the value as the provided type (T). | |
| template<typename T > | |
| simdjson_warn_unused simdjson_inline error_code | get (T &value) const noexcept |
| Get the value as the provided type (T). | |
| template<typename T > | |
| 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. | |
| operator bool () const noexcept(false) | |
| Read this element as a boolean. | |
| operator const char * () const noexcept(false) | |
| Read this element as a null-terminated UTF-8 string. | |
| operator std::string_view () const noexcept(false) | |
| Read this element as a null-terminated UTF-8 string. | |
| operator uint64_t () const noexcept(false) | |
| Read this element as an unsigned integer. | |
| operator int64_t () const noexcept(false) | |
| Read this element as an signed integer. | |
| operator double () const noexcept(false) | |
| Read this element as an double. | |
| operator array () const noexcept(false) | |
| Read this element as a JSON array. | |
| operator object () const noexcept(false) | |
| Read this element as a JSON object (key/value pairs). | |
| dom::array::iterator | begin () const noexcept(false) |
| Iterate over each element in this array. | |
| dom::array::iterator | end () const noexcept(false) |
| Iterate over each element in this array. | |
| simdjson_result< element > | operator[] (std::string_view key) const noexcept |
| Get the value associated with the given key. | |
| simdjson_result< element > | operator[] (const char *key) const noexcept |
| Get the value associated with the given key. | |
| simdjson_result< element > | operator[] (int) const noexcept=delete |
| simdjson_result< element > | at_pointer (const std::string_view json_pointer) const noexcept |
| Get the value associated with the given JSON pointer. | |
| simdjson_result< std::vector< element > > | at_path_with_wildcard (const std::string_view json_path) const noexcept |
| simdjson_result< element > | at_path (std::string_view json_path) const noexcept |
| Get the value associated with the given JSONPath expression. | |
| 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 following : | |
| simdjson_result< element > | at (size_t index) const noexcept |
| Get the value at the given index. | |
| simdjson_result< element > | at_key (std::string_view key) const noexcept |
| Get the value associated with the given key. | |
| 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. | |
| bool | operator< (const element &other) const noexcept |
| operator< defines a total order for element allowing to use them in ordered C++ STL containers | |
| bool | operator== (const element &other) const noexcept |
| operator== allows to verify if two element values reference the same JSON item | |
| template<> | |
| simdjson_warn_unused simdjson_inline error_code | get (element &value) const noexcept |
| template<> | |
| simdjson_result< array > | get () const noexcept |
| template<> | |
| simdjson_result< object > | get () const noexcept |
| template<> | |
| simdjson_result< const char * > | get () const noexcept |
| template<> | |
| simdjson_result< int64_t > | get () const noexcept |
| template<> | |
| simdjson_result< uint64_t > | get () const noexcept |
| template<> | |
| simdjson_result< double > | get () const noexcept |
| template<> | |
| simdjson_result< bool > | get () const noexcept |
A JSON element.
References an element in a JSON document, representing a JSON null, boolean, string, number, array or object.
|
noexcept |
Create a new, invalid element.
Definition at line 203 of file element-inl.h.
|
inlinenoexcept |
Version 0.4 of simdjson used an incorrect interpretation of the JSON Pointer standard and allowed the following :
dom::parser parser; element doc = parser.parse(R"({ "foo": { "a": [ 10, 20, 30 ] }})"_padded); doc.at("foo/a/1") == 20
Though it is intuitive, it is not compliant with RFC 6901 https://tools.ietf.org/html/rfc6901
For standard compliance, use the at_pointer function instead.
Definition at line 448 of file element-inl.h.
|
inlinenoexcept |
Get the value at the given index.
Definition at line 455 of file element-inl.h.
|
inlinenoexcept |
Get the value associated with the given key.
The key will be matched against unescaped JSON:
dom::parser parser; int64_t(parser.parse(R"({ "a
": 1 })"_padded)["a\n"]) == 1 parser.parse(R"({ "a
": 1 })"_padded)["a\\n"].get_uint64().error() == NO_SUCH_FIELD
Definition at line 458 of file element-inl.h.
|
inlinenoexcept |
Get the value associated with the given key in a case-insensitive manner.
Note: The key will be matched against unescaped JSON.
Definition at line 461 of file element-inl.h.
|
inlinenoexcept |
Get the value associated with the given JSONPath expression.
We only support JSONPath queries that trivially convertible to JSON Pointer queries: key names and array indices.
https://www.rfc-editor.org/rfc/rfc9535 (RFC 9535)
Definition at line 441 of file element-inl.h.
|
inlinenoexcept |
Definition at line 428 of file element-inl.h.
|
inlinenoexcept |
Get the value associated with the given JSON pointer.
We use the RFC 6901 https://tools.ietf.org/html/rfc6901 standard.
dom::parser parser; element doc = parser.parse(R"({ "foo": { "a": [ 10, 20, 30 ] }})"_padded); doc.at_pointer("/foo/a/1") == 20 doc.at_pointer("/foo")["a"].at(1) == 20 doc.at_pointer("")["foo"]["a"].at(1) == 20
It is allowed for a key to be the empty string:
dom::parser parser; object obj = parser.parse(R"({ "": { "a": [ 10, 20, 30 ] }})"_padded); obj.at_pointer("//a/1") == 20
Definition at line 407 of file element-inl.h.
|
inline |
Iterate over each element in this array.
| simdjson_error(INCORRECT_TYPE) | if the JSON element is not an array |
Definition at line 374 of file element-inl.h.
|
inline |
Iterate over each element in this array.
| simdjson_error(INCORRECT_TYPE) | if the JSON element is not an array |
Definition at line 377 of file element-inl.h.
|
inlinenoexcept |
Definition at line 336 of file element-inl.h.
|
inlinenoexcept |
Definition at line 336 of file element-inl.h.
|
inlinenoexcept |
Definition at line 336 of file element-inl.h.
|
inlinenoexcept |
Definition at line 336 of file element-inl.h.
|
inlinenoexcept |
Definition at line 336 of file element-inl.h.
|
inlinenoexcept |
Definition at line 336 of file element-inl.h.
|
inlinenoexcept |
Definition at line 336 of file element-inl.h.
|
inlinenoexcept |
Get the value as the provided type (T).
Supported types:
You may use get_double(), get_bool(), get_uint64(), get_int64(), get_object(), get_array() or get_string() instead.
| T | bool, double, uint64_t, int64_t, std::string_view, const char *, dom::array, dom::object |
|
noexcept |
Definition at line 326 of file element-inl.h.
|
noexcept |
Get the value as the provided type (T).
Supported types:
| T | bool, double, uint64_t, int64_t, std::string_view, const char *, dom::array, dom::object |
| value | The variable to set to the value. May not be set if there is an error. |
Definition at line 321 of file element-inl.h.
|
inlinenoexcept |
Cast this element to an array.
Definition at line 301 of file element-inl.h.
|
inlinenoexcept |
Cast this element to a bool.
Definition at line 212 of file element-inl.h.
|
inlinenoexcept |
Cast this element to a null-terminated C string.
The string is guaranteed to be valid UTF-8.
The length of the string is given by get_string_length(). Because JSON strings may contain null characters, it may be incorrect to use strlen to determine the string length.
It is possible to get a single string_view instance which represents both the string content and its length: see get_string().
Definition at line 221 of file element-inl.h.
|
inlinenoexcept |
Cast this element to a double floating-point.
Definition at line 279 of file element-inl.h.
|
inlinenoexcept |
Cast this element to a signed integer.
Definition at line 264 of file element-inl.h.
|
inlinenoexcept |
Cast this element to an object.
Definition at line 310 of file element-inl.h.
|
inlinenoexcept |
Cast this element to a string.
The string is guaranteed to be valid UTF-8.
Definition at line 241 of file element-inl.h.
|
inlinenoexcept |
Gives the length in bytes of the string.
It is possible to get a single string_view instance which represents both the string content and its length: see get_string().
Definition at line 231 of file element-inl.h.
|
inlinenoexcept |
Cast this element to an unsigned integer.
Definition at line 250 of file element-inl.h.
|
noexcept |
Tell whether the value can be cast to provided type (T).
Supported types:
| T | bool, double, uint64_t, int64_t, std::string_view, const char *, dom::array, dom::object |
Definition at line 336 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json array.
Equivalent to is<array>().
Definition at line 350 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json true or false.
Equivalent to is<bool>().
Definition at line 356 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json number that fits in a double.
Equivalent to is<double>().
Definition at line 355 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json number that fits in a signed 64-bit integer.
Equivalent to is<int64_t>().
Definition at line 353 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json null.
Definition at line 359 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json number.
Both integers and floating points will return true.
Definition at line 357 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json object.
Equivalent to is<object>().
Definition at line 351 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json string.
Equivalent to is<std::string_view>() or is<const char *>().
Definition at line 352 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json number that fits in an unsigned 64-bit integer.
Equivalent to is<uint64_t>().
Definition at line 354 of file element-inl.h.
|
inline |
Read this element as a JSON array.
| simdjson_error(INCORRECT_TYPE) | if the JSON element is not an array |
Definition at line 371 of file element-inl.h.
|
inline |
Read this element as a boolean.
| simdjson_error(INCORRECT_TYPE) | if the JSON element is not a boolean. |
Definition at line 365 of file element-inl.h.
|
inlineexplicit |
Read this element as a null-terminated UTF-8 string.
Be mindful that JSON allows strings to contain null characters.
Does not convert other types to a string; requires that the JSON type of the element was an actual string.
| simdjson_error(INCORRECT_TYPE) | if the JSON element is not a string. |
Definition at line 366 of file element-inl.h.
|
inline |
Read this element as an double.
| simdjson_error(INCORRECT_TYPE) | if the JSON element is not a number |
Definition at line 370 of file element-inl.h.
|
inline |
Read this element as an signed integer.
| simdjson_error(INCORRECT_TYPE) | if the JSON element is not an integer |
| simdjson_error(NUMBER_OUT_OF_RANGE) | if the integer does not fit in 64 bits |
Definition at line 369 of file element-inl.h.
|
inline |
Read this element as a JSON object (key/value pairs).
| simdjson_error(INCORRECT_TYPE) | if the JSON element is not an object |
Definition at line 372 of file element-inl.h.
|
inline |
Read this element as a null-terminated UTF-8 string.
Does not convert other types to a string; requires that the JSON type of the element was an actual string.
| simdjson_error(INCORRECT_TYPE) | if the JSON element is not a string. |
Definition at line 367 of file element-inl.h.
|
inline |
Read this element as an unsigned integer.
| simdjson_error(INCORRECT_TYPE) | if the JSON element is not an integer |
| simdjson_error(NUMBER_OUT_OF_RANGE) | if the integer does not fit in 64 bits or is negative |
Definition at line 368 of file element-inl.h.
|
inlinenoexcept |
operator< defines a total order for element allowing to use them in ordered C++ STL containers
Definition at line 464 of file element-inl.h.
|
inlinenoexcept |
operator== allows to verify if two element values reference the same JSON item
Definition at line 467 of file element-inl.h.
|
inlinenoexcept |
Get the value associated with the given key.
The key will be matched against unescaped JSON:
dom::parser parser; int64_t(parser.parse(R"({ "a
": 1 })"_padded)["a\n"]) == 1 parser.parse(R"({ "a
": 1 })"_padded)["a\\n"].get_uint64().error() == NO_SUCH_FIELD
Definition at line 386 of file element-inl.h.
|
inlinenoexcept |
Get the value associated with the given key.
The key will be matched against unescaped JSON:
dom::parser parser; int64_t(parser.parse(R"({ "a
": 1 })"_padded)["a\n"]) == 1 parser.parse(R"({ "a
": 1 })"_padded)["a\\n"].get_uint64().error() == NO_SUCH_FIELD
Definition at line 383 of file element-inl.h.
|
inlinenoexcept |
Get the value as the provided type (T), setting error if it's not the given type.
Supported types:
| T | bool, double, uint64_t, int64_t, std::string_view, const char *, dom::array, dom::object |
| value | The variable to set to the given type. value is undefined if there is an error. |
| error | The variable to store the error. error is set to error_code::SUCCEED if there is an error. |
Definition at line 331 of file element-inl.h.
|
inlinenoexcept |
The type of this element.
Definition at line 206 of file element-inl.h.