toJSON

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

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\"}");
fnstring toJSON(const var value, const Json5WriteOptions opts, ref Json5WriteScratch scratch) @safe

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