class JSONParser

Defined at line 27 of file ../../src/lib/json_parser/json_parser.h

A JSON parser utility class.

This class provides general facilities to parse a JSON file, and report

errors. If parsing succeeds, ReadFrom() returns a rapidjson::Document

representing the file. The class is agnostic to the actual structure of

the document -- client code is responsible for interpreting the

rapidjson::Document, which could contain any valid JSON.

Public Methods

void JSONParser ()

Defined at line 29 of file ../../src/lib/json_parser/json_parser.h

void JSONParser (JSONParser && )

Defined at line 30 of file ../../src/lib/json_parser/json_parser.h

JSONParser & operator= (JSONParser && )

Defined at line 31 of file ../../src/lib/json_parser/json_parser.h

rapidjson::Document ParseFromFile (const std::string & file)

Parses a JSON file. If reading or parsing the file fails, reports errors in

error_str(). May be called multiple times, for example on multiple files,

in which case any previous errors will be retained.

Defined at line 52 of file ../../src/lib/json_parser/json_parser.cc

rapidjson::Document ParseFromFileAt (int dirfd, const std::string & file)

Like |ParseFromFile|, but relative to a directory.

Defined at line 62 of file ../../src/lib/json_parser/json_parser.cc

rapidjson::Document ParseFromString (const std::string & data, const std::string & file)

Initialize the document from a JSON string |data|. If parsing fails,

reports errors in error_str(). |file| is not read, but it is used as the

prefix for lines in error_str(). May be called multiple times, for example

on multiple files, in which case any previous errors will be retained.

Defined at line 72 of file ../../src/lib/json_parser/json_parser.cc

void ParseFromDirectory (const std::string & path, fit::function<void (rapidjson::Document)> cb)

Initialize multiple documents from files in a directory. |cb| is

called for each file that parses. The traversal is not recursive, and all

files in the directory are expected to be JSON files. If the directory does

not exist, no error is reported, and no callbacks are called. Callers

wishing to identify such a state should stat the path themselves.

It is up to the caller to decide how to merge multiple documents.

Defined at line 83 of file ../../src/lib/json_parser/json_parser.cc

void ParseFromDirectoryAt (int dirfd, const std::string & path, fit::function<void (rapidjson::Document)> cb)

Like |ParseFromDirectory|, but relative to a directory.

Defined at line 88 of file ../../src/lib/json_parser/json_parser.cc

void CopyStringArray (const std::string & name, const rapidjson::Value & value, std::vector<std::string> * out)

Copies the string values from a |name|d |value| to the |out| vector.

Clears |out| and calls ReportError() if |value| does not refer to an array,

or if the array contains non-string values.

Defined at line 113 of file ../../src/lib/json_parser/json_parser.cc

bool HasError ()

Returns true if there was an error initializing the document.

Defined at line 143 of file ../../src/lib/json_parser/json_parser.cc

std::string error_str ()

If HasError() is true, returns a human-readable string describing the

error(s) initializing the document.

Defined at line 145 of file ../../src/lib/json_parser/json_parser.cc

void ReportError (const std::string & error)

Records an error initializing the object. Multiple errors may be recorded.

Defined at line 130 of file ../../src/lib/json_parser/json_parser.cc