parse

## `parse`

Return parsed JSON as a `value`.

### Synopsis

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

    value
    parse(
        string_view s,
        boost::system::error_code& ec,
        storage_ptr sp = {},
        parse_options const& opt = {}); (1)

    value
    parse(
        string_view s,
        std::error_code& ec,
        storage_ptr sp = {},
        parse_options const& opt = {}); (2)

    value
    parse(
        string_view s,
        storage_ptr sp = {},
        parse_options const& opt = {}); (3)

    value
    parse(
        std::istream& is,
        boost::system::error_code& ec,
        storage_ptr sp = {},
        parse_options const& opt = {}); (4)

    value
    parse(
        std::istream& is,
        std::error_code& ec,
        storage_ptr sp = {},
        parse_options const& opt = {}); (5)

    value
    parse(
        std::istream& is,
        storage_ptr sp = {},
        parse_options const& opt = {}); (6)

### Description

This function parses input in one step to produce a complete JSON `value`. If the input does not contain a complete serialized JSON, an error occurs. In this case (1), (2), (4), and (5) return a null value that uses the default memory resource, and set `ec` to the corresponding error value. (3) and (6) throw an exception.

### Complexity

- (1), (2), (3) linear in `s.size()`.

- (4), (5), (6) linear in the size of consumed input.

### Exception Safety

- (1), (2), (3) strong guarantee.

- (4), (5), (6) basic guarantee.

(3), (6) throw `boost::system::system_error` on failed parse. Calls to `memory_resource::allocate` may throw. The stream `is` may throw as described by `std::ios::exceptions`.

### Return Value

A value representing the parsed JSON.

### Parameters

Name | Description
--- | ---
`s` | The string to parse.
`ec` | Set to the error, if any occurred.
`sp` | The memory resource that the new value and all of its elements will use.
`opt` | The options for the parser. If this parameter is omitted, the parser will accept only standard JSON.
`is` | The stream to read from.

### See Also

`parse_options`, `stream_parser`, `value::operator>>`.

Convenience header <boost/json.hpp>

Edit this page