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.
NaN and Infinity are not representable in JSON and are emitted as null.- This function allocates while building the resulting
string and is not @nogc. Examples
import ddn.data.json5 : toJSON;
import ddn.var : var;
var m;
m["a"] = "x";
assert(toJSON(m) == "{\"a\":\"x\"}");
Parameters
value | Value to serialize. |
opts | Writer options; writeMode is forced to JSON. |
Returns
Strict JSON text representation of value.