Boost.JSON Logo

PrevUpHomeNext

basic_parser

An incremental SAX parser for serialized JSON.

Synopsis

Defined in header <boost/json/detail/basic_parser.hpp>

class basic_parser
Member Functions

Name

Description

depth

Returns the current depth of the JSON being parsed.

is_complete

Return true if a complete JSON has been parsed.

max_depth

Returns the maximum allowed depth of input JSON.

Set the maximum allowed depth of input JSON.

~basic_parser

Destructor.

Protected Member Functions

Name

Description

reset

Reset the state, to parse a new document.

write_some

Parse JSON incrementally.

Description

This implements a SAX-style parser. The serialized JSON is presented to the parser by calling to write_some, write, and finish. The parsing events are realized through member function calls to a handler passed as an argument to the write functions.

The parser may dynamically allocate intermediate storage as needed to accommodate the nesting level of the JSON being parsed. This storage is freed when the parser is destroyed, allowing the parser to cheaply re-use this memory when parsing subsequent JSONs, improving performance.

Usage

Users who wish to parse JSON into the DOM container value will not use this class directly; instead they will create an instance of parser and use that instead. Alternatively, they may call the function parse. This class is designed for users who wish to perform custom actions instead of building a value. For example, to produce a DOM from an external library.

To use this class it is necessary to create a derived class which calls reset at the beginning of parsing a new JSON, and then calls write_some one or more times with the serialized JSON.

Remarks

The parser is strict: no extensions are supported. Only compliant JSON is recognized.

See Also

parse, parser

Convenience header <boost/json.hpp>


PrevUpHomeNext