simdjson  3.11.0
Ridiculously Fast JSON
simdjson::dom::array Class Reference

JSON array. More...

Classes

class  iterator
 

Public Member Functions

simdjson_inline array () noexcept
 Create a new, invalid array.
 
iterator begin () const noexcept
 Return the first array element. More...
 
iterator end () const noexcept
 One past the last array element. More...
 
size_t size () const noexcept
 Get the size of the array (number of immediate children). More...
 
size_t number_of_slots () const noexcept
 Get the total number of slots used by this array on the tape. More...
 
simdjson_result< elementat_pointer (std::string_view json_pointer) const noexcept
 Get the value associated with the given JSON pointer. More...
 
simdjson_result< elementat_path (std::string_view json_path) const noexcept
 Get the value associated with the given JSONPath expression. More...
 
simdjson_result< elementat (size_t index) const noexcept
 Get the value at the given index. More...
 
 operator element () const noexcept
 Implicitly convert object to element.
 

Detailed Description

JSON array.

Definition at line 13 of file array.h.

Member Function Documentation

◆ at()

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

Get the value at the given index.

This function has linear-time complexity and is equivalent to the following:

size_t i=0; for (auto element : *this) { if (i == index) { return element; } i++; } return INDEX_OUT_OF_BOUNDS;

Avoid calling the at() function repeatedly.

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 130 of file array-inl.h.

◆ at_path()

simdjson_result< element > simdjson::dom::array::at_path ( std::string_view  json_path) const
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

Returns
The value associated with the given JSONPath expression, or:
  • INVALID_JSON_POINTER if the JSONPath to JSON Pointer conversion fails
  • 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

Definition at line 124 of file array-inl.h.

◆ at_pointer()

simdjson_result< element > simdjson::dom::array::at_pointer ( std::string_view  json_pointer) const
inlinenoexcept

Get the value associated with the given JSON pointer.

We use the RFC 6901 https://tools.ietf.org/html/rfc6901 standard, interpreting the current node as the root of its own JSON document.

dom::parser parser; array a = parser.parse(R"([ { "foo": { "a": [ 10, 20, 30 ] }} ])"_padded); a.at_pointer("/0/foo/a/1") == 20 a.at_pointer("0")["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 83 of file array-inl.h.

◆ begin()

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

Return the first array element.

Part of the std::iterable interface.

Definition at line 67 of file array-inl.h.

◆ end()

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

One past the last array element.

Part of the std::iterable interface.

Definition at line 71 of file array-inl.h.

◆ number_of_slots()

size_t simdjson::dom::array::number_of_slots ( ) const
inlinenoexcept

Get the total number of slots used by this array on the tape.

Note that this is not the same thing as size(), which reports the number of actual elements within an array (not counting its children).

Since an element can use 1 or 2 slots on the tape, you can only use this to figure out the total size of an array (including its children, recursively) if you know its structure ahead of time.

Definition at line 79 of file array-inl.h.

◆ size()

size_t simdjson::dom::array::size ( ) const
inlinenoexcept

Get the size of the array (number of immediate children).

It is a saturated value with a maximum of 0xFFFFFF: if the value is 0xFFFFFF then the size is 0xFFFFFF or greater.

Definition at line 75 of file array-inl.h.


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