1#ifndef SIMDJSON_GENERIC_ONDEMAND_OBJECT_H
3#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4#define SIMDJSON_GENERIC_ONDEMAND_OBJECT_H
5#include "simdjson/generic/ondemand/base.h"
6#include "simdjson/generic/implementation_simdjson_result_base.h"
7#include "simdjson/generic/ondemand/value_iterator.h"
9#if SIMDJSON_STATIC_REFLECTION && SIMDJSON_SUPPORTS_CONCEPTS
10#include "simdjson/generic/ondemand/json_string_builder.h"
15namespace SIMDJSON_IMPLEMENTATION {
28 simdjson_inline
object() noexcept = default;
183#if SIMDJSON_SUPPORTS_CONCEPTS
184 template <
typename Func>
185 requires std::invocable<Func, value>
187 template <
typename Func>
236#if SIMDJSON_SUPPORTS_CONCEPTS
244 template <
typename T>
245 simdjson_warn_unused simdjson_inline
error_code get(T &out)
246 noexcept(custom_deserializable<T, object> ? nothrow_custom_deserializable<T, object> :
true) {
247 static_assert(custom_deserializable<T, object>);
248 return deserialize(*
this, out);
256 template <
typename T>
258 noexcept(custom_deserializable<T,
value> ? nothrow_custom_deserializable<T,
value> : true)
260 static_assert(std::is_default_constructible<T>::value,
"The specified type is not default constructible.");
262 SIMDJSON_TRY(get<T>(out));
266#if SIMDJSON_STATIC_REFLECTION
291 template<constevalutil::fixed_string... FieldNames,
typename T>
292 requires(std::is_class_v<T> && (
sizeof...(FieldNames) > 0))
293 simdjson_warn_unused simdjson_inline
error_code extract_into(T& out) &
noexcept;
301 static simdjson_inline
simdjson_result<
object> start(value_iterator &iter) noexcept;
302 static simdjson_inline
simdjson_result<
object> start_root(value_iterator &iter) noexcept;
303 static simdjson_inline
simdjson_result<
object> started(value_iterator &iter) noexcept;
304 static simdjson_inline
object resume(const value_iterator &iter) noexcept;
305 simdjson_inline
object(const value_iterator &iter) noexcept;
307 simdjson_warn_unused simdjson_inline
error_code find_field_raw(const std::string_view key) noexcept;
309 value_iterator iter{};
312 friend class document;
313 friend struct simdjson_result<
object>;
339#if SIMDJSON_SUPPORTS_CONCEPTS
340 template <
typename Func>
341 requires std::invocable<Func, SIMDJSON_IMPLEMENTATION::ondemand::value>
343 template <
typename Func>
345 simdjson_inline
error_code for_each_at_path_with_wildcard(std::string_view json_path, Func&& callback)
noexcept;
350 #if SIMDJSON_SUPPORTS_CONCEPTS
356 if constexpr (std::is_same_v<T, SIMDJSON_IMPLEMENTATION::ondemand::object>) {
359 return first.get<T>();
362 simdjson_warn_unused simdjson_inline
error_code get(T& out)
noexcept {
364 if constexpr (std::is_same_v<T, SIMDJSON_IMPLEMENTATION::ondemand::object>) {
367 SIMDJSON_TRY( first.get<T>(out) );
372#if SIMDJSON_STATIC_REFLECTION
374 template<constevalutil::fixed_string... FieldNames,
typename T>
375 requires(std::is_class_v<T> && (
sizeof...(FieldNames) > 0))
376 simdjson_warn_unused simdjson_inline
error_code extract_into(T& out)
noexcept {
378 return first.extract_into<FieldNames...>(out);
A forward-only JSON object field iterator.
simdjson_inline object() noexcept=default
Create a new invalid object.
error_code for_each_at_path_with_wildcard(std::string_view json_path, Func &&callback) noexcept
Call the provided callback for each value matching the given JSONPath expression with wildcard suppor...
simdjson_inline simdjson_result< value > find_field_unordered(std::string_view key) &noexcept
Look up a field by name on an object, without regard to key order.
simdjson_inline simdjson_result< std::string_view > raw_json() noexcept
Consumes the object and returns a string_view instance corresponding to the object as represented in ...
simdjson_warn_unused simdjson_inline error_code consume() noexcept
Go to the end of the object, no matter where you are right now.
simdjson_inline simdjson_result< value > find_field(std::string_view key) &noexcept
Look up a field by name on an object (order-sensitive).
simdjson_result< bool > is_empty() &noexcept
This method scans the beginning of the object and checks whether the object is empty.
simdjson_result< bool > reset() &noexcept
Reset the iterator so that we are pointing back at the beginning of the object.
simdjson_result< value > at_path(std::string_view json_path) noexcept
Get the value associated with the given JSONPath expression.
simdjson_result< value > at_pointer(std::string_view json_pointer) noexcept
Get the value associated with the given JSON pointer.
simdjson_inline simdjson_result< object_iterator > begin() noexcept
Get an iterator to the start of the object.
simdjson_inline simdjson_result< size_t > count_fields() &noexcept
This method scans the object and counts the number of key-value pairs.
An ephemeral JSON value returned during iteration.
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
The result of a simdjson operation that could fail.
The result of a simdjson operation that could fail.
simdjson_inline error_code error() const noexcept
The error.
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.