Skip to content

Commit

Permalink
Merge pull request #8 from vibe-d/fix_json_to
Browse files Browse the repository at this point in the history
Fix compilation of Json.to!(Json[]) and Json.to!(Json[string]).
  • Loading branch information
s-ludwig committed Jun 10, 2024
2 parents bdba9fc + 86ab039 commit 8140d45
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 8140d45

Please sign in to comment.