parse_into

Parse a JSON text into a user-defined object.

Synopsis

Defined in header <boost/json/parse_into.hpp>.

template<
    class V>
void
parse_into(
    V& v,
    string_view sv,
    boost::system::error_code& ec,
    parse_options const& opt = {}); (1)

template<
    class V>
void
parse_into(
    V& v,
    string_view sv,
    std::error_code& ec,
    parse_options const& opt = {}); (2)

template<
    class V>
void
parse_into(
    V& v,
    string_view sv,
    parse_options const& opt = {}); (3)

template<
    class V>
void
parse_into(
    V& v,
    std::istream& is,
    boost::system::error_code& ec,
    parse_options const& opt = {}); (4)

template<
    class V>
void
parse_into(
    V& v,
    std::istream& is,
    std::error_code& ec,
    parse_options const& opt = {}); (5)

template<
    class V>
void
parse_into(
    V& v,
    std::istream& is,
    parse_options const& opt = {}); (6)

Description

This function parses a string and fills an object provided by the user. If the buffer does not contain a complete serialized JSON text, an error occurs. In this case v may be partially filled. Overloads (1)(3) consume the entire string s. Overloads (4)(6) read characters from the input stream is. All overloads consume all available characters, and produce an error if there are non-whitespace characters after the initial JSON.

The function supports default constructible types satisfying SequenceContainer, arrays, arithmetic types, bool, std::tuple, std::pair, std::optional, std::variant, std::nullptr_t, and structs and enums described using Boost.Describe.

Complexity

  • (1)(3) linear in sv.size().

  • (4)(6) linear in the size of consumed input.

Exception Safety

Basic guarantee. Calls to memory_resource::allocate may throw. Overloads (3) and (6) throw boost::system::system_error on error. The stream is may throw as described by std::ios::exceptions.

Parameters

Name Description

v

The type to parse into.

sv

The string to parse.

ec

Set to the error, if any occurred.

opt

The options for the parser. If this parameter is omitted, the parser will accept only standard JSON.

is

The stream to read from.

Convenience header <boost/json.hpp>