parseJSON5Sax

fnbool parseJSON5Sax(const(char)[] input, ref Json5SaxHandler handler, out Json5Error err, const Json5Policy policy = Json5Policy.init) @safe

Parse JSON5 text and emit SAX-style events into handler.

This parser uses the existing lexer and does not build a full var tree. It is intended for memory-efficient processing of large documents.

Examples

import ddn.data.json5 : Json5SaxHandler, parseJSON5Sax, Json5Error;
import ddn.var : var;

size_t keys = 0;
size_t scalars = 0;
Json5SaxHandler h;
h.onKey = (const string k) @safe { ++keys; };
h.onValue = (const var v) @safe { ++scalars; };

Json5Error err;
assert(parseJSON5Sax("{a:1,b:[2,3]}", h, err));
assert(keys == 2);
assert(scalars == 3);

Returns

true on success; false with err populated on failure.