JsonCpp project page | Classes | Namespace | JsonCpp home page

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

Build a CharReader implementation. More...

`#include <json/reader.h>`

Inheritance diagram for Json::CharReaderBuilder:
Collaboration diagram for Json::CharReaderBuilder:

## Public Member Functions
bool | validate (Json::Value *invalid) const
| Configuration of this builder.
Value & | operator[] (const String &key)
| A simple way to update a specific setting.
Public Member Functions inherited from Json::CharReader::Factory
virtual | ~Factory ()=default
virtual CharReader * | newCharReader () const =0
| Allocate a CharReader via operator new().

## Static Public Member Functions
static void | setDefaults (Json::Value *settings)
| Called by ctor, but you can use this to reset settings_.
static void | strictMode (Json::Value *settings)
| Same as old Features::strictMode().
static void | ecma404Mode (Json::Value *settings)
| ECMA-404 mode.

## Detailed Description

Build a CharReader implementation.

Usage:

using namespace Json;
CharReaderBuilder builder;
builder["collectComments"] = false;
Value value;
String errs;
bool ok = parseFromStream(builder, std::cin, &value, &errs);
Json::CharReaderBuilder
Build a CharReader implementation.
Definition reader.h:317
Json::Value
Represents a JSON value.
Definition value.h:207
Json
JSON (JavaScript Object Notation).
Definition allocator.h:16
Json::String
std::basic_string< char, std::char_traits< char >, Allocator< char > > String
Definition config.h:135
Json::parseFromStream
bool parseFromStream(CharReader::Factory const &, IStream &, Value *root, String *errs)
Consume entire stream and use its begin/end.
Definition json_reader.cpp:2006

Definition at line 317 of file reader.h.

## Member Function Documentation

## ◆ ecma404Mode()

void Json::CharReaderBuilder::ecma404Mode | ( | Json::Value * | settings | ) |
| static

ECMA-404 mode.

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

Remarks
  Defaults:
  (*settings)["allowComments"] = false;
  (*settings)["allowTrailingCommas"] = false;
  (*settings)["strictRoot"] = false;
  (*settings)["allowDroppedNullPlaceholders"] = false;
  (*settings)["allowNumericKeys"] = false;
  (*settings)["allowSingleQuotes"] = false;
  (*settings)["stackLimit"] = 256;
  (*settings)["failIfExtra"] = true;
  (*settings)["rejectDupKeys"] = false;
  (*settings)["allowSpecialFloats"] = false;
  (*settings)["skipBom"] = false;

[CharReaderBuilderECMA404Mode]

[CharReaderBuilderECMA404Mode]

Definition at line 1977 of file json_reader.cpp.

References ecma404Mode().

Referenced by ecma404Mode().

Here is the caller graph for this function:

## ◆ operator[]()

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

A simple way to update a specific setting.

Definition at line 1940 of file json_reader.cpp.

References operator[]().

Referenced by operator[]().

Here is the caller graph for this function:

## ◆ setDefaults()

void Json::CharReaderBuilder::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)["collectComments"] = true;
  (*settings)["allowComments"] = true;
  (*settings)["allowTrailingCommas"] = true;
  (*settings)["strictRoot"] = false;
  (*settings)["allowDroppedNullPlaceholders"] = false;
  (*settings)["allowNumericKeys"] = false;
  (*settings)["allowSingleQuotes"] = false;
  (*settings)["stackLimit"] = 256;
  (*settings)["failIfExtra"] = false;
  (*settings)["rejectDupKeys"] = false;
  (*settings)["allowSpecialFloats"] = false;
  (*settings)["skipBom"] = true;

[CharReaderBuilderDefaults]

[CharReaderBuilderDefaults]

Definition at line 1960 of file json_reader.cpp.

References setDefaults().

Referenced by setDefaults().

Here is the caller graph for this function:

## ◆ strictMode()

void Json::CharReaderBuilder::strictMode | ( | Json::Value * | settings | ) |
| static

Same as old Features::strictMode().

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

Remarks
  Defaults:
  (*settings)["allowComments"] = false;
  (*settings)["allowTrailingCommas"] = false;
  (*settings)["strictRoot"] = true;
  (*settings)["allowDroppedNullPlaceholders"] = false;
  (*settings)["allowNumericKeys"] = false;
  (*settings)["allowSingleQuotes"] = false;
  (*settings)["stackLimit"] = 256;
  (*settings)["failIfExtra"] = true;
  (*settings)["rejectDupKeys"] = true;
  (*settings)["allowSpecialFloats"] = false;
  (*settings)["skipBom"] = true;

[CharReaderBuilderStrictMode]

[CharReaderBuilderStrictMode]

Definition at line 1944 of file json_reader.cpp.

References strictMode().

Referenced by strictMode().

Here is the caller graph for this function:

## ◆ validate()

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

Configuration of this builder.

These are case-sensitive. Available settings (case-sensitive):

- "collectComments": false or true
  - true to collect comment and allow writing them back during serialization, false to discard comments. This parameter is ignored if allowComments is false.
- "allowComments": false or true
  - true if comments are allowed.
- "allowTrailingCommas": false or true
  - true if trailing commas in objects and arrays are allowed.
- "strictRoot": false or true
  - true if root must be either an array or an object value
- "allowDroppedNullPlaceholders": false or true
  - true if dropped null placeholders are allowed. (See StreamWriterBuilder.)
- "allowNumericKeys": false or true
  - true if numeric object keys are allowed.
- "allowSingleQuotes": false or true
  - true if '' are allowed for strings (both keys and values)
- "stackLimit": integer
  - Exceeding stackLimit (recursive depth of readValue()) will cause an exception.
  - This is a security issue (seg-faults caused by deeply nested JSON), so the default is low.
- "failIfExtra": false or true
  - If true, parse() returns false when extra non-whitespace trails the JSON value in the input string.
- "rejectDupKeys": false or true
  - If true, parse() returns false when a key is duplicated within an object.
- "allowSpecialFloats": false or true
  - If true, special float values (NaNs and infinities) are allowed and their values are lossfree restorable.
- "skipBom": false or true
  - If true, if the input starts with the Unicode byte order mark (BOM), it is skipped.

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

See also
  setDefaults() */ Json::Value settings_;

CharReaderBuilder(); ~CharReaderBuilder() override;

CharReader* newCharReader() const override;

/**

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

Definition at line 1913 of file json_reader.cpp.

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

Referenced by validate().

Here is the caller graph for this function:

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

- include/json/reader.h
- src/lib_json/json_reader.cpp