json_parser.h
Source: samples/common/core/json_parser.h
Minimal recursive-descent JSON parser (header-only, C++).
Provides just enough functionality to parse configuration files used by the Merlin benchmark harness: strings, ints, doubles, and dependency arrays. No dynamic allocation beyond std::string / std::vector.
Structs
JsonParser
Lightweight, non-owning JSON pull-parser.
The caller points p and end at a UTF-8 buffer and then calls the various Parse / Skip helpers. The parser advances p as it consumes tokens; on failure it returns false and leaves p in an unspecified position.
Members
| Name | Type | Description |
|---|---|---|
p |
const char * |
|
end |
const char * |
Methods
SkipWs()
Advance past whitespace characters.
Consume(char expected)
Consume a single expected character (after skipping whitespace).
Parameters:
| Name | Type | Description |
|---|---|---|
expected |
char |
The character to match. |
Returns: true if the character was found and consumed.
ParseString(std::string *out)
Parse a JSON string (including surrounding quotes).
Parameters:
| Name | Type | Description |
|---|---|---|
out |
std::string * |
Receives the unescaped string content. |
Returns: true on success.
ParseInt(int *out)
Parse a JSON integer.
Parameters:
| Name | Type | Description |
|---|---|---|
out |
int * |
Receives the parsed value (set to 0 on failure). |
Returns: true on success.
ParseDouble(double *out)
Parse a JSON number as a double.
Parameters:
| Name | Type | Description |
|---|---|---|
out |
double * |
Receives the parsed value (set to 0.0 on failure). |
Returns: true on success.
SkipValue()
Skip over an arbitrary JSON value (string, number, object, array, bool, null).
SkipArray()
Skip over a JSON array and all of its elements.
SkipObject()
Skip over a JSON object and all of its key-value pairs.