simdjson 4.0.7
Ridiculously Fast JSON
Loading...
Searching...
No Matches
simdjson::dom::object Class Reference

JSON object. More...

#include <object.h>

Classes

class  iterator
 

Public Member Functions

simdjson_inline object () noexcept
 Create a new, invalid object.
 
iterator begin () const noexcept
 Return the first key/value pair.
 
iterator end () const noexcept
 One past the last key/value pair.
 
size_t size () const noexcept
 Get the size of the object (number of keys).
 
simdjson_result< elementoperator[] (std::string_view key) const noexcept
 Get the value associated with the given key.
 
simdjson_result< elementoperator[] (const char *key) const noexcept
 Get the value associated with the given key.
 
simdjson_result< elementoperator[] (int) const noexcept=delete
 
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_key (std::string_view key) const noexcept
 Get the value associated with the given key.
 
std::vector< element > & get_values (std::vector< element > &out) const noexcept
 Gets the values associated with keys of an object This function has linear-time complexity: the keys are checked one by one.
 
simdjson_result< elementat_key_case_insensitive (std::string_view key) const noexcept
 Get the value associated with the given key in a case-insensitive manner.
 
 operator element () const noexcept
 Implicitly convert object to element.
 

Detailed Description

JSON object.

Definition at line 16 of file object.h.

Constructor & Destructor Documentation

◆ object()

simdjson_inline simdjson::dom::object::object ( )
noexcept

Create a new, invalid object.

Definition at line 83 of file object-inl.h.

Member Function Documentation

◆ at_key()

simdjson_result< element > simdjson::dom::object::at_key ( 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; 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

This function has linear-time complexity: the keys are checked one by one.

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

Definition at line 246 of file object-inl.h.

◆ at_key_case_insensitive()

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

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

It is only guaranteed to work over ASCII inputs.

Note: The key will be matched against unescaped JSON.

This function has linear-time complexity: the keys are checked one by one.

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

Definition at line 270 of file object-inl.h.

◆ at_path()

simdjson_result< element > simdjson::dom::object::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 149 of file object-inl.h.

◆ at_path_with_wildcard()

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

Adds support for JSONPath expression with wildcards '*'.

Definition at line 175 of file object-inl.h.

◆ at_pointer()

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

◆ begin()

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

Return the first key/value pair.

Part of the std::iterable interface.

Definition at line 85 of file object-inl.h.

◆ end()

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

One past the last key/value pair.

Part of the std::iterable interface.

Definition at line 89 of file object-inl.h.

◆ get_values()

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

Gets the values associated with keys of an object This function has linear-time complexity: the keys are checked one by one.

Returns
the values associated with each key of an object

Definition at line 256 of file object-inl.h.

◆ operator element()

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

Implicitly convert object to element.

Definition at line 280 of file object-inl.h.

◆ operator[]() [1/2]

simdjson_result< element > simdjson::dom::object::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; 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

This function has linear-time complexity: the keys are checked one by one.

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 101 of file object-inl.h.

◆ operator[]() [2/2]

simdjson_result< element > simdjson::dom::object::operator[] ( 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; 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

This function has linear-time complexity: the keys are checked one by one.

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 98 of file object-inl.h.

◆ process_json_path_of_child_elements()

void simdjson::dom::object::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 155 of file object-inl.h.

◆ size()

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

Get the size of the object (number of keys).

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 93 of file object-inl.h.


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