import mir.format: stringBuf; import mir.bignum.integer; auto buffer = stringBuf; auto ser = jsonSerializer((()@trusted=>&buffer)(), 3); auto state0 = ser.structBegin; ser.putKey("null"); ser.putValue(null); ser.putKey("array"); auto state1 = ser.listBegin(); ser.elemBegin; ser.putValue(null); ser.elemBegin; ser.putValue(123); ser.elemBegin; ser.putValue(12300000.123); ser.elemBegin; ser.putValue("\t"); ser.elemBegin; ser.putValue("\r"); ser.elemBegin; ser.putValue("\n"); ser.elemBegin; ser.putValue(BigInt!2(1234567890)); ser.listEnd(state1); ser.structEnd(state0); assert(buffer.data == `{"null":null,"array":[null,123,1.2300000123e+7,"\t","\r","\n",1234567890]}`);
import std.array; import mir.bignum.integer; auto app = appender!string; auto ser = jsonSerializer!" "(&app); auto state0 = ser.structBegin; ser.putKey("null"); ser.putValue(null); ser.putKey("array"); auto state1 = ser.listBegin(); ser.elemBegin; ser.putValue(null); ser.elemBegin; ser.putValue(123); ser.elemBegin; ser.putValue(12300000.123); ser.elemBegin; ser.putValue("\t"); ser.elemBegin; ser.putValue("\r"); ser.elemBegin; ser.putValue("\n"); ser.elemBegin; ser.putValue(BigInt!2("1234567890")); ser.listEnd(state1); ser.structEnd(state0); assert(app.data == `{ "null": null, "array": [ null, 123, 1.2300000123e+7, "\t", "\r", "\n", 1234567890 ] }`, app.data);
Creates JSON serialization back-end. Use sep equal to "\t" or " " for pretty formatting.