36template <
typename TContainer>
40 using element_type =
typename TContainer::value_type;
50 return std::unexpected(opened.error());
57 detail::reserve_if_possible(out, opened->element_count());
59 bool recovered =
false;
68 for (std::size_t idx = 0U; from.
good(); ++idx)
75 type == ast_node_type::document_end || type == ast_node_type::error)
77 return context.problem(
context.problem_path(from),
"Unterminated array");
93 context.note_value_consumed(from);
94 return std::unexpected(ast_node_type::error);
103 auto element = [&] () -> std::expected<element_type, ast_node_type>
107 return context.extract<element_type>(from);
116 return std::unexpected(element.error());
119 context.skip_failed_value(from);
123 out.insert(end(out), *std::move(element));
141 if (type == ast_node_type::array_end)
146 else if (type == ast_node_type::document_end || type == ast_node_type::error)
157 context.note_value_consumed(from);
163 return context.problem(
context.problem_path(from),
"Unterminated array");
170 for (
const element_type& x : from)
171 out.push_back(
context.to_json(x));
Copyright (c) 2015-2026 by Travis Gockel.
Utilities for directly dealing with a JSON AST.
An adapter for the type T.
The beginning of an kind::array ([).
An adapter for container types.
virtual std::expected< TContainer, ast_node_type > create(extraction_context &context, reader &from) const override
Create an instance of T by reading from.
Provides extra information to routines used for extraction and serialization.
A reader instance reads from some form of JSON source (probably a string) and converts it into a JSON...
bool next_value() noexcept
Go to one past the value this reader is on.
ast_node_type current_type() const
Get the type of the current AST node, which is always current().type().
bool next_token() noexcept
Go to the next token.
bool good() const
Check if this reader is still good to read from.
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Copyright (c) 2014-2020 by Travis Gockel.
#define JSONV_NODISCARD
Warn if the caller discards the result of this function.
JSONV_PUBLIC value array()
Create an empty array value.
Definition of the reserve_if_possible utility.
Conversion between C++ types and JSON values.