parseJsonSax

fnbool parseJsonSax(const(char)[] input, ref JsonSaxHandler handler, out JsonError err, const JsonPolicy policy = JsonPolicy.init) @safe

Parse 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.

Parameters

inputThe JSON text to parse.
handlerThe event handler receiving parsing events.
errOutput parameter for error information on failure.
policyPolicy controlling parser behavior.

Returns

true on success; false with err populated on failure.

Examples

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);