toJSON5

fnstring toJSON5(const var value, const Json5WriteOptions opts = Json5WriteOptions.init) @safe

Serialize a var to JSON5 text using the provided opts.

Notes:

  • This function allocates while building the resulting string and is not @nogc.

    Examples

    import ddn.var;
    var m; m["a"] = 1; m["b"] = 2;
    auto s = ddn.data.json5.toJSON5(m); // "{a:1,b:2}"

    Parameters

    valueValue to serialize.
    optsWriter options controlling layout and escaping.

    Returns

    JSON5 text representation of value.
fnstring toJSON5(const var value, const Json5WriteOptions opts, ref Json5WriteScratch scratch) @safe

Serialize a var to JSON5 text using the provided opts and reusable scratch buffers.

This overload allows callers to reuse temporary key-sorting buffers across repeated serializations to reduce allocations.

Parameters

valueValue to serialize.
optsWriter options controlling layout and escaping.
scratchReusable writer scratch buffers.

Returns

JSON5 text representation of value.