Skip to content

Commit

Permalink
Fix compilation of Json.to!(Json[]) and Json.to!(Json[string]).
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Jun 10, 2024
1 parent bdba9fc commit 86ab039
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions source/vibe/data/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -770,12 +770,12 @@ struct Json {
}
} else static if( is(T == Json[]) ){
switch( m_type ){
default: return Json([this]);
default: return [this];
case Type.array: return m_array;
}
} else static if( is(T == Json[string]) ){
switch( m_type ){
default: return Json(["value": this]);
default: return ["value": this];
case Type.object: return m_object;
}
} else static if( is(T == BigInt) ){
Expand All @@ -795,6 +795,13 @@ struct Json {
} else static assert(0, "JSON can only be cast to (bool, long, std.bigint.BigInt, double, string, Json[] or Json[string]. Not "~T.stringof~".");
}

unittest {
assert(Json(42).to!string == "42");
assert(Json("42").to!int == 42);
assert(Json(42).to!(Json[]) == [Json(42)]);
assert(Json(42).to!(Json[string]) == ["value": Json(42)]);
}

/**
Performs unary operations on the JSON value.
Expand Down

0 comments on commit 86ab039

Please sign in to comment.