import asdf; import std.array; import std.bigint; import std.format: singleSpec; auto app = appender!string; auto ser = jsonSerializer(&app.put!(const(char)[])); auto state0 = ser.structBegin; ser.putEscapedKey("null"); ser.putValue(null); ser.putEscapedKey("array"); auto state1 = ser.listBegin(); ser.elemBegin; ser.putValue(null); ser.elemBegin; ser.putValue(123); ser.elemBegin; ser.putNumberValue(12300000.123, singleSpec("%.10e")); ser.elemBegin; ser.putValue("\t"); ser.elemBegin; ser.putValue("\r"); ser.elemBegin; ser.putValue("\n"); ser.elemBegin; ser.putNumberValue(BigInt("1234567890")); ser.listEnd(state1); ser.structEnd(state0); ser.flush; assert(app.data == `{"null":null,"array":[null,123,1.2300000123e+07,"\t","\r","\n",1234567890]}`);
Creates JSON serialization back-end. Use sep equal to "\t" or " " for pretty formatting.