true on success; false with err populated on failure.bool parseJsonSax(const(char)[] input, ref JsonSaxHandler handler, out JsonError err,
const JsonPolicy policy = JsonPolicy.init) @safeParse JSON text and emit SAX-style events into handler.
This parser uses the lexer and does not build a full var tree. It is intended for memory-efficient processing of large documents.
input | The JSON text to parse. |
handler | The event handler receiving parsing events. |
err | Output parameter for error information on failure. |
policy | Policy controlling parser behavior. |
true on success; false with err populated on failure.import ddn.data.json : JsonSaxHandler, parseJsonSax, JsonError;
import ddn.var : var;
size_t keys = 0;
size_t scalars = 0;
JsonSaxHandler h;
h.onKey = (const string k) @safe { ++keys; };
h.onValue = (const var v) @safe { ++scalars; };
JsonError err;
assert(parseJsonSax(`{"a":1,"b":[2,3]}`, h, err));
assert(keys == 2);
assert(scalars == 3);