From 86ab03944ef33dc9d10db8ee3a8da6c96e5cec5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 10 Jun 2024 13:35:56 +0200 Subject: [PATCH] Fix compilation of Json.to!(Json[]) and Json.to!(Json[string]). --- source/vibe/data/json.d | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/vibe/data/json.d b/source/vibe/data/json.d index adef059..856883a 100644 --- a/source/vibe/data/json.d +++ b/source/vibe/data/json.d @@ -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) ){ @@ -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.