# Poco::JSON

# class PrintHandler

Library: JSON
Package: JSON
Header: Poco/JSON/PrintHandler.h

## Description

PrintHandler formats and prints the JSON object to either user-provided std::ostream or standard output. If indent is zero, the output is a condensed JSON string, otherwise, the proper indentation is applied to elements.

## Inheritance

Direct Base Classes: Handler

All Base Classes: Handler

## Member Summary

Member Functions: comma, endArray, endObject, key, null, reset, setIndent, startArray, startObject, value

Inherited Functions: asStruct, asVar, endArray, endObject, key, null, reset, startArray, startObject, value

## Types Aliases

### Ptr

using Ptr = SharedPtr < PrintHandler >;

## Constructors

### PrintHandler

PrintHandler(
unsigned indent = 0,
int options = Poco::JSON_WRAP_STRINGS
);

Creates the PrintHandler.

### PrintHandler

PrintHandler(
std::ostream & out,
unsigned indent = 0,
int options = Poco::JSON_WRAP_STRINGS
);

Creates the PrintHandler.

## Destructor

### ~PrintHandler

~PrintHandler() override;

Destroys the PrintHandler.

## Member Functions

### comma

void comma();

A comma is read; it will be written to the output as "true" or "false".

### endArray

void endArray() override;

The parser has read a ]; the array is closed.

See also: Poco::JSON::Handler::endArray()

### endObject

void endObject() override;

The parser has read a '}'; the object is closed.

See also: Poco::JSON::Handler::endObject()

### key

void key(
const std::string & k
) override;

A key of an object is read; it will be written to the output, followed by a ':'. If indent is greater than zero, the colon is padded by a space before and after.

See also: Poco::JSON::Handler::key()

### null

void null() override;

A null value is read; "null" will be written to the output.

See also: Poco::JSON::Handler::null()

### reset

void reset() override;

Resets the handler state.

See also: Poco::JSON::Handler::reset()

### setIndent

void setIndent(
unsigned indent
);

Sets indentation.

### startArray

void startArray() override;

The parser has read a [; a new array will be started. If indent is greater than zero, a newline will be appended.

See also: Poco::JSON::Handler::startArray()

### startObject

void startObject() override;

The parser has read a '{'; a new object is started. If indent is greater than zero, a newline will be appended.

See also: Poco::JSON::Handler::startObject()

### value

void value(
int v
) override;

An integer value is read.

See also: Poco::JSON::Handler::value()

### value

void value(
unsigned v
) override;

An unsigned value is read. This will only be triggered if the value cannot fit into a signed int.

See also: Poco::JSON::Handler::value()

### value

void value(
Int64 v
) override;

A 64-bit integer value is read; it will be written to the output.

See also: Poco::JSON::Handler::value()

### value

void value(
UInt64 v
) override;

An unsigned 64-bit integer value is read; it will be written to the output.

See also: Poco::JSON::Handler::value()

### value

void value(
const std::string & value
) override;

A string value is read; it will be formatted and written to the output.

See also: Poco::JSON::Handler::value()

### value

void value(
double d
) override;

A double value is read; it will be written to the output.

See also: Poco::JSON::Handler::value()

### value

void value(
bool b
) override;

A boolean value is read; it will be written to the output.

See also: Poco::JSON::Handler::value()

## Variables

### JSON_PRINT_FLAT

static const unsigned JSON_PRINT_FLAT = 0;