Skip to content

Json

Has

bool Json::Has(const string &in json, const string &in path)

Whether a JSON text has a value at a dotted path ("entries.0.name": object keys and array indices). Requires host 0.26.0.

Example
if (Json::Has(body, "entry.rank"))
    Log::Info("ranked");

String

string Json::String(const string &in json, const string &in path, const string &in fallback = "")

The value at a path as text (numbers and true/false written out), or fallback. Requires host 0.26.0.

Example
string name = Json::String(body, "entries.0.name", "?");

Number

double Json::Number(const string &in json, const string &in path, double fallback = 0)

The number at a path, or fallback. Requires host 0.26.0.

Example
double ms = Json::Number(body, "entries.0.timeMs");

Bool

bool Json::Bool(const string &in json, const string &in path, bool fallback = false)

The true/false at a path, or fallback. Requires host 0.26.0.

Example
bool ok = Json::Bool(body, "ok");

Count

int Json::Count(const string &in json, const string &in path)

How many items an array (or members an object) at a path has, -1 if there is none. Requires host 0.26.0.

Example
for (int i = 0; i < Json::Count(body, "entries"); i++)
    Log::Info(Json::String(body, "entries." + i + ".name"));

Quote

string Json::Quote(const string &in text)

A text as a JSON string (quoted, escaped), for building request bodies. Requires host 0.26.0.

Example
string body = "{\"track\":" + Json::Quote(track) + "}";