import ddn.data.json5 : toJSON;
import ddn.var : var;
var m;
m["a"] = "x";
assert(toJSON(m) == "{\"a\":\"x\"}");toJSON
Serialize a var to strict JSON text.
This is a convenience wrapper around toJSON5 that forces writeMode to Json5WriteMode.JSON.
Notes:
- Keys are always quoted.
- Strings are always double-quoted.
- Trailing commas are disabled.
NaNandInfinityare not representable in JSON and are emitted asnull.- This function allocates while building the resulting
stringand is not
@nogc.
Examples
Serialize a var to strict JSON text using the provided opts and reusable scratch buffers.