simdjson
3.11.0
Ridiculously Fast JSON
|
A JSON element. More...
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. More... | |
simdjson_result< object > | get_object () const noexcept |
Cast this element to an object. More... | |
simdjson_result< const char * > | get_c_str () const noexcept |
Cast this element to a null-terminated C string. More... | |
simdjson_result< size_t > | get_string_length () const noexcept |
Gives the length in bytes of the string. More... | |
simdjson_result< std::string_view > | get_string () const noexcept |
Cast this element to a string. More... | |
simdjson_result< int64_t > | get_int64 () const noexcept |
Cast this element to a signed integer. More... | |
simdjson_result< uint64_t > | get_uint64 () const noexcept |
Cast this element to an unsigned integer. More... | |
simdjson_result< double > | get_double () const noexcept |
Cast this element to a double floating-point. More... | |
simdjson_result< bool > | get_bool () const noexcept |
Cast this element to a bool. More... | |
bool | is_array () const noexcept |
Whether this element is a json array. More... | |
bool | is_object () const noexcept |
Whether this element is a json object. More... | |
bool | is_string () const noexcept |
Whether this element is a json string. More... | |
bool | is_int64 () const noexcept |
Whether this element is a json number that fits in a signed 64-bit integer. More... | |
bool | is_uint64 () const noexcept |
Whether this element is a json number that fits in an unsigned 64-bit integer. More... | |
bool | is_double () const noexcept |
Whether this element is a json number that fits in a double. More... | |
bool | is_number () const noexcept |
Whether this element is a json number. More... | |
bool | is_bool () const noexcept |
Whether this element is a json true or false . More... | |
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). More... | |
template<typename T > | |
simdjson_result< T > | get () const noexcept |
Get the value as the provided type (T). More... | |
template<typename T > | |
simdjson_warn_unused simdjson_inline error_code | get (T &value) const noexcept |
Get the value as the provided type (T). More... | |
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. More... | |
operator bool () const noexcept(false) | |
Read this element as a boolean. More... | |
operator const char * () const noexcept(false) | |
Read this element as a null-terminated UTF-8 string. More... | |
operator std::string_view () const noexcept(false) | |
Read this element as a null-terminated UTF-8 string. More... | |
operator uint64_t () const noexcept(false) | |
Read this element as an unsigned integer. More... | |
operator int64_t () const noexcept(false) | |
Read this element as an signed integer. More... | |
operator double () const noexcept(false) | |
Read this element as an double. More... | |
operator array () const noexcept(false) | |
Read this element as a JSON array. More... | |
operator object () const noexcept(false) | |
Read this element as a JSON object (key/value pairs). More... | |
dom::array::iterator | begin () const noexcept(false) |
Iterate over each element in this array. More... | |
dom::array::iterator | end () const noexcept(false) |
Iterate over each element in this array. More... | |
simdjson_result< element > | operator[] (std::string_view key) const noexcept |
Get the value associated with the given key. More... | |
simdjson_result< element > | operator[] (const char *key) const noexcept |
Get the value associated with the given key. More... | |
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. More... | |
simdjson_result< element > | at_path (std::string_view json_path) const noexcept |
Get the value associated with the given JSONPath expression. More... | |
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 : More... | |
simdjson_result< element > | at (size_t index) const noexcept |
Get the value at the given index. More... | |
simdjson_result< element > | at_key (std::string_view key) const noexcept |
Get the value associated with the given key. More... | |
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. More... | |
bool | operator< (const element &other) const noexcept |
operator< defines a total order for element allowing to use them in ordered C++ STL containers More... | |
bool | operator== (const element &other) const noexcept |
operator== allows to verify if two element values reference the same JSON item More... | |
template<> | |
simdjson_warn_unused simdjson_inline error_code | get (element &value) const noexcept |
template<typename T > | |
void | tie (T &value, error_code &error) &&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.
|
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 428 of file element-inl.h.
|
inlinenoexcept |
Get the value at the given index.
Definition at line 435 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 438 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 441 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://datatracker.ietf.org/doc/html/draft-normington-jsonpath-00
Definition at line 421 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 401 of file element-inl.h.
|
inlinenoexcept |
Iterate over each element in this array.
simdjson_error(INCORRECT_TYPE) | if the JSON element is not an array |
Definition at line 368 of file element-inl.h.
|
inlinenoexcept |
Iterate over each element in this array.
simdjson_error(INCORRECT_TYPE) | if the JSON element is not an array |
Definition at line 371 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 |
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 315 of file element-inl.h.
|
inlinenoexcept |
Cast this element to an array.
Definition at line 295 of file element-inl.h.
|
inlinenoexcept |
Cast this element to a bool.
Definition at line 206 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 215 of file element-inl.h.
|
inlinenoexcept |
Cast this element to a double floating-point.
Definition at line 273 of file element-inl.h.
|
inlinenoexcept |
Cast this element to a signed integer.
Definition at line 258 of file element-inl.h.
|
inlinenoexcept |
Cast this element to an object.
Definition at line 304 of file element-inl.h.
|
inlinenoexcept |
Cast this element to a string.
The string is guaranteed to be valid UTF-8.
Definition at line 235 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 225 of file element-inl.h.
|
inlinenoexcept |
Cast this element to an unsigned integer.
Definition at line 244 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 330 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json array.
Equivalent to is<array>().
Definition at line 344 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json true
or false
.
Equivalent to is<bool>().
Definition at line 350 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 349 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 347 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json number.
Both integers and floating points will return true.
Definition at line 351 of file element-inl.h.
|
inlinenoexcept |
Whether this element is a json object.
Equivalent to is<object>().
Definition at line 345 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 346 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 348 of file element-inl.h.
|
inlinenoexcept |
Read this element as a JSON array.
simdjson_error(INCORRECT_TYPE) | if the JSON element is not an array |
Definition at line 365 of file element-inl.h.
|
inlinenoexcept |
Read this element as a boolean.
simdjson_error(INCORRECT_TYPE) | if the JSON element is not a boolean. |
Definition at line 359 of file element-inl.h.
|
inlineexplicitnoexcept |
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 360 of file element-inl.h.
|
inlinenoexcept |
Read this element as an double.
simdjson_error(INCORRECT_TYPE) | if the JSON element is not a number |
Definition at line 364 of file element-inl.h.
|
inlinenoexcept |
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 363 of file element-inl.h.
|
inlinenoexcept |
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 366 of file element-inl.h.
|
inlinenoexcept |
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 361 of file element-inl.h.
|
inlinenoexcept |
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 362 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 444 of file element-inl.h.
|
inlinenoexcept |
operator== allows to verify if two element values reference the same JSON item
Definition at line 447 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 380 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 377 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. |