parseJSON5

fnbool parseJSON5(out var value, const(char)[] input, out Json5Error err) @safe

Parse JSON5 text from input into value.

Notes:

  • This function performs allocations while building the resulting var tree

and is therefore not @nogc.

Returns

true on success; false with err populated on failure.

Examples

import ddn.var; // construct a simple object in JSON5
ddn.data.json5.Json5Error e;
var v; assert(ddn.data.json5.parseJSON5(v, "{name:'Bob',list:[1,2,3], note: 'hi'}", e));
assert(v.contains("name") && v.get("name", "").as!string == "Bob");
fnbool parseJSON5(out var value, const(char)[] input, out Json5Error err, Json5Policy policy) @safe

Parse JSON5 text into a var value with custom policy.

When policy.useStrictJsonParser is true, this function first attempts to parse using the faster strict JSON parser (ddn.data.json). If that fails (e.g., because the input uses JSON5 features), it falls back to the full JSON5 parser.

Parameters

valueOutput parameter for the parsed value.
inputJSON5 text to parse.
errOutput parameter for error information on failure.
policyPolicy controlling parser behavior.

Returns

true on success; false with err populated on failure.
fnbool parseJSON5(out var value, const(char)[] input, Json5Reviver reviver, out Json5Error err) @safe

Parse JSON5 text and apply reviver to each value.

Notes:

  • This overload can allocate (parser output + user reviver work) and cannot

be @nogc.

Returns

true on success; false with err populated on parse failure or

if reviver throws.

fnvar parseJSON5(const(char)[] input) @safe

Convenience overload that parses JSON5 text and returns the resulting value.

Note

returns var.init on failure.
fnbool parseJSON5(out var value, ref File file, out Json5Error err, const Json5Policy policy = Json5Policy.init, size_t chunkSize = 16_384) @safe

Parse JSON5 data from an open std.stdio.File.

The file is read incrementally in chunks and the parsed value is returned in value.

Returns

true on success; false with err populated on failure.
fnbool parseJSON5(R)(out var value, R input, out Json5Error err, const Json5Policy policy = Json5Policy.init, size_t chunkSize = 16_384) if ( isInputRange!R && (is(ElementType!R == ubyte) || isSomeChar!(ElementType!R)) ) @safe

Parse JSON5 data from an input range of char or ubyte.

This overload is useful for streaming sources, range pipelines, or when the input is not naturally available as a contiguous array.

Returns

true on success; false with err populated on failure.