Skip to content

Commit

Permalink
Merge pull request #1737 from tchaloupka/fix_#1735
Browse files Browse the repository at this point in the history
Output null instead of undefined with Json.undefined serialization
  • Loading branch information
s-ludwig committed Sep 2, 2017
1 parent ea98e7d commit 4e6e12b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion source/vibe/data/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}

/**
Expand All @@ -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;
Expand Down

0 comments on commit 4e6e12b

Please sign in to comment.