simdjson  0.3.1
Ridiculously Fast JSON
Public Member Functions | List of all members
simdjson::dom::element Class Reference

A JSON element. More...

Inheritance diagram for simdjson::dom::element:

Public Member Functions

really_inline element () noexcept
 Create a new, invalid element.
 
really_inline element_type type () const noexcept
 The type of this element.
 
really_inline bool is_null () const noexcept
 Whether this element is a json null.
 
template<typename T >
really_inline bool is () const noexcept
 Tell whether the value can be cast to the given primitive type. More...
 
template<typename T >
really_inline simdjson_result< T > get () const noexcept
 Get the value as the given primitive 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 string. More...
 
 operator std::string_view () const noexcept(false)
 Read this element as a null-terminated 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[] (const 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 > at (const std::string_view &json_pointer) const noexcept
 Get the value associated with the given JSON pointer. More...
 
simdjson_result< element > at (size_t index) const noexcept
 Get the value at the given index. More...
 
simdjson_result< element > at_key (const std::string_view &key) const noexcept
 Get the value associated with the given key. More...
 
simdjson_result< element > at_key_case_insensitive (const std::string_view &key) const noexcept
 Get the value associated with the given key in a case-insensitive manner. More...
 
template<>
simdjson_result< bool > get () const noexcept
 
template<>
simdjson_result< const char * > get () const noexcept
 
template<>
simdjson_result< uint64_t > get () const noexcept
 
template<>
simdjson_result< int64_t > get () const noexcept
 
template<>
simdjson_result< double > get () const noexcept
 
template<>
simdjson_result< array > get () const noexcept
 
template<>
simdjson_result< object > get () const noexcept
 

Detailed Description

A JSON element.

References an element in a JSON document, representing a JSON null, boolean, string, number, array or object.

Definition at line 380 of file document.h.

Member Function Documentation

◆ at() [1/2]

simdjson_result< element > simdjson::dom::element::at ( const std::string_view &  json_pointer) const
inlinenoexcept

Get the value associated with the given JSON pointer.

dom::parser parser; element doc = parser.parse(R"({ "foo": { "a": [ 10, 20, 30 ] }})"); doc.at("/foo/a/1") == 20 doc.at("/")["foo"]["a"].at(1) == 20 doc.at("")["foo"]["a"].at(1) == 20

Returns
The value associated with the given JSON pointer, or:
  • NO_SUCH_FIELD if a field does not exist in an object
  • INDEX_OUT_OF_BOUNDS if an array index is larger than an array length
  • INCORRECT_TYPE if a non-integer is used to access an array
  • INVALID_JSON_POINTER if the JSON pointer is invalid and cannot be parsed

Definition at line 886 of file document.h.

◆ at() [2/2]

simdjson_result< element > simdjson::dom::element::at ( size_t  index) const
inlinenoexcept

Get the value at the given index.

Returns
The value at the given index, or:
  • INDEX_OUT_OF_BOUNDS if the array index is larger than an array length

Definition at line 896 of file document.h.

◆ at_key()

simdjson_result< element > simdjson::dom::element::at_key ( const std::string_view &  key) const
inlinenoexcept

Get the value associated with the given key.

The key will be matched against unescaped JSON:

dom::parser parser; parser.parse(R"({ "a
": 1 })")["a\n"].get<uint64_t>().value == 1 parser.parse(R"({ "a
": 1 })")["a\\n"].get<uint64_t>().error == NO_SUCH_FIELD

Returns
The value associated with this field, or:
  • NO_SUCH_FIELD if the field does not exist in the object

Definition at line 899 of file document.h.

◆ at_key_case_insensitive()

simdjson_result< element > simdjson::dom::element::at_key_case_insensitive ( const std::string_view &  key) const
inlinenoexcept

Get the value associated with the given key in a case-insensitive manner.

Note: The key will be matched against unescaped JSON.

Returns
The value associated with this field, or:
  • NO_SUCH_FIELD if the field does not exist in the object

Definition at line 902 of file document.h.

◆ begin()

array::iterator simdjson::dom::element::begin ( ) const
inlinenoexcept

Iterate over each element in this array.

Returns
The beginning of the iteration.
Exceptions
simdjson_error(INCORRECT_TYPE)if the JSON element is not an array

Definition at line 871 of file document.h.

◆ end()

array::iterator simdjson::dom::element::end ( ) const
inlinenoexcept

Iterate over each element in this array.

Returns
The end of the iteration.
Exceptions
simdjson_error(INCORRECT_TYPE)if the JSON element is not an array

Definition at line 874 of file document.h.

◆ get()

template<typename T >
really_inline simdjson_result<T> simdjson::dom::element::get ( ) const
noexcept

Get the value as the given primitive type.

Supported types:

  • Boolean: bool
  • Number: double, uint64_t, int64_t
  • String: std::string_view, const char *
  • Array: array
Returns
The value cast to the given type, or: INCORRECT_TYPE if the value cannot be cast to the given type.

◆ is()

template<typename T >
really_inline bool simdjson::dom::element::is
noexcept

Tell whether the value can be cast to the given primitive type.

Supported types:

  • Boolean: bool
  • Number: double, uint64_t, int64_t
  • String: std::string_view, const char *
  • Array: array

Definition at line 855 of file document.h.

◆ operator array()

simdjson::dom::element::operator array ( ) const
inlinenoexcept

Read this element as a JSON array.

Returns
The JSON array.
Exceptions
simdjson_error(INCORRECT_TYPE)if the JSON element is not an array

Definition at line 868 of file document.h.

◆ operator bool()

simdjson::dom::element::operator bool ( ) const
inlinenoexcept

Read this element as a boolean.

Returns
The boolean value
Exceptions
simdjson_error(INCORRECT_TYPE)if the JSON element is not a boolean.

Definition at line 862 of file document.h.

◆ operator const char *()

simdjson::dom::element::operator const char * ( ) const
inlineexplicitnoexcept

Read this element as a null-terminated string.

Does not convert other types to a string; requires that the JSON type of the element was an actual string.

Returns
The string value.
Exceptions
simdjson_error(INCORRECT_TYPE)if the JSON element is not a string.

Definition at line 863 of file document.h.

◆ operator double()

simdjson::dom::element::operator double ( ) const
inlinenoexcept

Read this element as an double.

Returns
The double value.
Exceptions
simdjson_error(INCORRECT_TYPE)if the JSON element is not a number
simdjson_error(NUMBER_OUT_OF_RANGE)if the integer doesn't fit in 64 bits or is negative

Definition at line 867 of file document.h.

◆ operator int64_t()

simdjson::dom::element::operator int64_t ( ) const
inlinenoexcept

Read this element as an signed integer.

Returns
The integer value.
Exceptions
simdjson_error(INCORRECT_TYPE)if the JSON element is not an integer
simdjson_error(NUMBER_OUT_OF_RANGE)if the integer doesn't fit in 64 bits

Definition at line 866 of file document.h.

◆ operator object()

simdjson::dom::element::operator object ( ) const
inlinenoexcept

Read this element as a JSON object (key/value pairs).

Returns
The JSON object.
Exceptions
simdjson_error(INCORRECT_TYPE)if the JSON element is not an object

Definition at line 869 of file document.h.

◆ operator std::string_view()

simdjson::dom::element::operator std::string_view ( ) const
inlinenoexcept

Read this element as a null-terminated string.

Does not convert other types to a string; requires that the JSON type of the element was an actual string.

Returns
The string value.
Exceptions
simdjson_error(INCORRECT_TYPE)if the JSON element is not a string.

Definition at line 864 of file document.h.

◆ operator uint64_t()

simdjson::dom::element::operator uint64_t ( ) const
inlinenoexcept

Read this element as an unsigned integer.

Returns
The integer value.
Exceptions
simdjson_error(INCORRECT_TYPE)if the JSON element is not an integer
simdjson_error(NUMBER_OUT_OF_RANGE)if the integer doesn't fit in 64 bits or is negative

Definition at line 865 of file document.h.

◆ operator[]() [1/2]

simdjson_result< element > simdjson::dom::element::operator[] ( const char *  key) const
inlinenoexcept

Get the value associated with the given key.

The key will be matched against unescaped JSON:

dom::parser parser; parser.parse(R"({ "a
": 1 })")["a\n"].get<uint64_t>().value == 1 parser.parse(R"({ "a
": 1 })")["a\\n"].get<uint64_t>().error == NO_SUCH_FIELD

Returns
The value associated with this field, or:
  • NO_SUCH_FIELD if the field does not exist in the object
  • INCORRECT_TYPE if this is not an object

Definition at line 883 of file document.h.

◆ operator[]() [2/2]

simdjson_result< element > simdjson::dom::element::operator[] ( const std::string_view &  key) const
inlinenoexcept

Get the value associated with the given key.

The key will be matched against unescaped JSON:

dom::parser parser; parser.parse(R"({ "a
": 1 })")["a\n"].get<uint64_t>().value == 1 parser.parse(R"({ "a
": 1 })")["a\\n"].get<uint64_t>().error == NO_SUCH_FIELD

Returns
The value associated with this field, or:
  • NO_SUCH_FIELD if the field does not exist in the object
  • INCORRECT_TYPE if this is not an object

Definition at line 880 of file document.h.


The documentation for this class was generated from the following file: