serializer

## `serializer`

A serializer for JSON.

### Synopsis

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

    class serializer;

### Member Functions

Name | Description
--- | ---
`done` | Check if the serialization is complete.
`read` | Read the next buffer of serialized JSON.
`reset` | Reset the serializer for a new element.
`serializer` [constructor] | Constructors.
`~serializer` [destructor] | Destructor.

### Description

This class traverses an instance of a library type and emits serialized JSON text by filling in one or more caller-provided buffers. To use, declare a variable and call `reset` with a pointer to the variable you want to serialize. Then call `read` over and over until `done` returns `true`.

### Example

This demonstrates how the serializer may be used to print a JSON value to an output stream.

    void print( std::ostream& os, value const& jv)
    {
        serializer sr;
        sr.reset( &jv );
        while( ! sr.done() )
        {
            char buf[ 4000 ];
            os << sr.read( buf );
        }
    }

### Thread Safety

The same instance may not be accessed concurrently.

### Non-Standard JSON

The `serialize_options` structure optionally provided upon construction is used to enable non-standard JSON extensions. A default-constructed `serialize_options` doesn’t enable any extensions.

### See Also

`serialize`.

Convenience header <boost/json.hpp>.

Edit this page