simdjson 4.2.2
Ridiculously Fast JSON
Loading...
Searching...
No Matches
simdjson::dom::array Class Reference

JSON array. More...

#include <array.h>

Classes

class  iterator
 

Public Member Functions

simdjson_inline array () noexcept
 Create a new, invalid array.
 
iterator begin () const noexcept
 Return the first array element.
 
iterator end () const noexcept
 One past the last array element.
 
size_t size () const noexcept
 Get the size of the array (number of immediate children).
 
size_t number_of_slots () const noexcept
 Get the total number of slots used by this array on the tape.
 
simdjson_result< elementat_pointer (std::string_view json_pointer) const noexcept
 Get the value associated with the given JSON pointer.
 
void process_json_path_of_child_elements (std::vector< element >::iterator &current, std::vector< element >::iterator &end, const std::string_view &path_suffix, std::vector< element > &accumulator) const noexcept
 Recursive function which processes the JSON path of each child element.
 
simdjson_result< std::vector< element > > at_path_with_wildcard (std::string_view json_path) const noexcept
 Adds support for JSONPath expression with wildcards '*'.
 
simdjson_result< elementat_path (std::string_view json_path) const noexcept
 Get the value associated with the given JSONPath expression.
 
simdjson_result< elementat (size_t index) const noexcept
 Get the value at the given index.
 
std::vector< element > & get_values (std::vector< element > &out) const noexcept
 Gets the values of items in an array element This function has linear-time complexity: the values are checked one by one.
 
 operator element () const noexcept
 Implicitly convert object to element.
 

Detailed Description

JSON array.

Definition at line 15 of file array.h.

Constructor & Destructor Documentation

◆ array()

simdjson_inline simdjson::dom::array::array ( )
noexcept

Create a new, invalid array.

Definition at line 76 of file array-inl.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 228 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://www.rfc-editor.org/rfc/rfc9535 (RFC 9535)

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

◆ at_path_with_wildcard()

simdjson_result< std::vector< element > > simdjson::dom::array::at_path_with_wildcard ( std::string_view  json_path) const
inlinenoexcept

Adds support for JSONPath expression with wildcards '*'.

Definition at line 162 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 94 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 78 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 82 of file array-inl.h.

◆ get_values()

std::vector< element > & simdjson::dom::array::get_values ( std::vector< element > &  out) const
inlinenoexcept

Gets the values of items in an array element This function has linear-time complexity: the values are checked one by one.

Returns
The child elements of an array

Definition at line 238 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 90 of file array-inl.h.

◆ operator element()

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

Implicitly convert object to element.

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

◆ process_json_path_of_child_elements()

void simdjson::dom::array::process_json_path_of_child_elements ( std::vector< element >::iterator &  current,
std::vector< element >::iterator &  end,
const std::string_view &  path_suffix,
std::vector< element > &  accumulator 
) const
inlinenoexcept

Recursive function which processes the JSON path of each child element.

Definition at line 141 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 86 of file array-inl.h.


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