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

JSON object. More...

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. More...
 
iterator end () const noexcept
 One past the last key/value pair. More...
 
size_t size () const noexcept
 Get the size of the object (number of keys). More...
 
simdjson_result< elementoperator[] (std::string_view key) const noexcept
 Get the value associated with the given key. More...
 
simdjson_result< elementoperator[] (const char *key) const noexcept
 Get the value associated with the given key. More...
 
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. 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_key (std::string_view key) const noexcept
 Get the value associated with the given key. More...
 
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. More...
 
 operator element () const noexcept
 Implicitly convert object to element.
 

Detailed Description

JSON object.

Definition at line 14 of file object.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 146 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 158 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://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 140 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 95 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 76 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 80 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 92 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 89 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 84 of file object-inl.h.


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