From 4e6e12b8651e712dafd2da2769eae0e5c8d15b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 16 May 2017 10:39:35 +0200 Subject: [PATCH] Merge pull request #1737 from tchaloupka/fix_#1735 Output null instead of undefined with Json.undefined serialization --- source/vibe/data/json.d | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/vibe/data/json.d b/source/vibe/data/json.d index 3cfb1f92d9..5c96bfb2bb 100644 --- a/source/vibe/data/json.d +++ b/source/vibe/data/json.d @@ -1877,6 +1877,12 @@ struct JsonStringSerializer(R, bool pretty = false) unittest { assert(serializeToJsonString(double.nan) == "null"); + assert(serializeToJsonString(Json()) == "null"); + assert(serializeToJsonString(Json(["bar":Json("baz"),"foo":Json()])) == `{"bar":"baz"}`); + + struct Foo{Json bar = Json();} + Foo f; + assert(serializeToJsonString(f) == `{"bar":null}`); } /** @@ -1896,7 +1902,7 @@ void writeJsonString(R, bool pretty = false)(ref R dst, in Json json, size_t lev // if( isOutputRange!R && is(ElementEncodingType!R == char) ) { final switch( json.type ){ - case Json.Type.undefined: dst.put("undefined"); break; + case Json.Type.undefined: dst.put("null"); break; case Json.Type.null_: dst.put("null"); break; case Json.Type.bool_: dst.put(cast(bool)json ? "true" : "false"); break; case Json.Type.int_: formattedWrite(dst, "%d", json.get!long); break;