JsonCpp project page | Classes | Namespace | JsonCpp home page

Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Json::StreamWriterBuilder Class Reference

Build a StreamWriter implementation. More...

`#include <json/writer.h>`

Inheritance diagram for Json::StreamWriterBuilder:
Collaboration diagram for Json::StreamWriterBuilder:

## Public Member Functions
| StreamWriterBuilder ()
| ~StreamWriterBuilder () override
StreamWriter * | newStreamWriter () const override
bool | validate (Json::Value *invalid) const
Value & | operator[] (const String &key)
| A simple way to update a specific setting.
Public Member Functions inherited from Json::StreamWriter::Factory
virtual | ~Factory ()

## Static Public Member Functions
static void | setDefaults (Json::Value *settings)
| Called by ctor, but you can use this to reset settings_.

## Public Attributes
Json::Value | settings_
| Configuration of this builder.

## Detailed Description

Build a StreamWriter implementation.

Usage:

using namespace Json;
Value value = ...;
StreamWriterBuilder builder;
builder["commentStyle"] = "None";
builder["indentation"] = " "; // or whatever you like
std::unique_ptr<Json::StreamWriter> writer(
builder.newStreamWriter());
writer->write(value, &std::cout);
std::cout << std::endl; // add lf and flush
Json::StreamWriterBuilder::newStreamWriter
StreamWriter * newStreamWriter() const override
Definition json_writer.cpp:1167
Json::StreamWriterBuilder::StreamWriterBuilder
StreamWriterBuilder()
Definition json_writer.cpp:1165
Json::Value
Represents a JSON value.
Definition value.h:194
Json
JSON (JavaScript Object Notation).
Definition allocator.h:15

Definition at line 90 of file writer.h.

## Constructor & Destructor Documentation

## ◆ StreamWriterBuilder()

Json::StreamWriterBuilder::StreamWriterBuilder | ( |  | ) |

Definition at line 1165 of file json_writer.cpp.

References setDefaults(), and settings_.

## ◆ ~StreamWriterBuilder()

Json::StreamWriterBuilder::~StreamWriterBuilder | ( |  | ) |
| override default

References newStreamWriter(), operator[](), setDefaults(), and validate().

## Member Function Documentation

## ◆ newStreamWriter()

StreamWriter * Json::StreamWriterBuilder::newStreamWriter | ( |  | ) | const
| override virtual

Exceptions

  std::exception | if something goes wrong (e.g. invalid settings)

Implements Json::StreamWriter::Factory.

Definition at line 1167 of file json_writer.cpp.

References Json::decimalPlaces, settings_, and Json::significantDigits.

Referenced by Json::operator<<(), and ~StreamWriterBuilder().

Here is the caller graph for this function:

## ◆ operator[]()

Value & Json::StreamWriterBuilder::operator[] | ( | const String & | key | ) |

A simple way to update a specific setting.

Definition at line 1233 of file json_writer.cpp.

References settings_.

Referenced by ~StreamWriterBuilder().

Here is the caller graph for this function:

## ◆ setDefaults()

void Json::StreamWriterBuilder::setDefaults | ( | Json::Value * | settings | ) |
| static

Called by ctor, but you can use this to reset settings_.

Precondition
  'settings' != NULL (but Json::null is fine)

Remarks
  Defaults:
  (*settings)["commentStyle"] = "All";
  (*settings)["indentation"] = "\t";
  (*settings)["enableYAMLCompatibility"] = false;
  (*settings)["dropNullPlaceholders"] = false;
  (*settings)["useSpecialFloats"] = false;
  (*settings)["emitUTF8"] = false;
  (*settings)["precision"] = 17;
  (*settings)["precisionType"] = "significant";

[StreamWriterBuilderDefaults]

[StreamWriterBuilderDefaults]

Definition at line 1237 of file json_writer.cpp.

Referenced by StreamWriterBuilder(), and ~StreamWriterBuilder().

Here is the caller graph for this function:

## ◆ validate()

bool Json::StreamWriterBuilder::validate | ( | Json::Value * | invalid | ) | const

Returns
  true if 'settings' are legal and consistent; otherwise, indicate bad settings via 'invalid'.

Definition at line 1210 of file json_writer.cpp.

References Json::Value::empty(), and settings_.

Referenced by ~StreamWriterBuilder().

Here is the caller graph for this function:

## Member Data Documentation

## ◆ settings_

Json::Value Json::StreamWriterBuilder::settings_

Configuration of this builder.

Available settings (case-sensitive):

- "commentStyle": "None" or "All"
- "indentation": "<anything>".
- Setting this to an empty string also omits newline characters.
- "enableYAMLCompatibility": false or true
- slightly change the whitespace around colons
- "dropNullPlaceholders": false or true
- Drop the "null" string from the writer's output for nullValues. Strictly speaking, this is not valid JSON. But when the output is being fed to a browser's JavaScript, it makes for smaller output and the browser can handle the output just fine.
- "useSpecialFloats": false or true
- If true, outputs non-finite floating point values in the following way: NaN values as "NaN", positive infinity as "Infinity", and negative infinity as "-Infinity".
- "precision": int
- Number of precision digits for formatting of real values.
- "precisionType": "significant"(default) or "decimal"
- Type of precision for formatting of real values.
- "emitUTF8": false or true
- If true, outputs raw UTF8 strings instead of escaping them.

You can examine 'settings_` yourself to see the defaults. You can also write and read them just like any JSON Value.

See also
  setDefaults()

Definition at line 122 of file writer.h.

Referenced by newStreamWriter(), operator[](), StreamWriterBuilder(), and validate().

The documentation for this class was generated from the following files:

- include/json/writer.h
- src/lib_json/json_writer.cpp