Skip to content

Commit

Permalink
Treat "undefined" as "null" when converting Json arrays to string. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Jul 19, 2014
1 parent 4ba9c59 commit 0f87041
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions source/vibe/data/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -1552,14 +1552,14 @@ void writeJsonString(R, bool pretty = false)(ref R dst, in Json json, size_t lev
dst.put('[');
bool first = true;
foreach (ref const Json e; json) {
if( e.type == Json.Type.undefined ) continue;
if( !first ) dst.put(",");
first = false;
static if (pretty) {
dst.put('\n');
foreach (tab; 0 .. level+1) dst.put('\t');
}
writeJsonString!(R, pretty)(dst, e, level+1);
if (e.type == Json.Type.undefined) dst.put("null");
else writeJsonString!(R, pretty)(dst, e, level+1);
}
static if (pretty) {
if (json.length > 0) {
Expand Down Expand Up @@ -1614,6 +1614,16 @@ unittest {
}`);
}

unittest { // #735
auto a = Json.emptyArray;
a ~= "a";
a ~= Json();
a ~= "b";
a ~= null;
a ~= "c";
assert(a.toString() == `["a",null,"b",null,"c"]`);
}

unittest {
auto a = Json.emptyArray;
a ~= Json(1);
Expand Down

0 comments on commit 0f87041

Please sign in to comment.