From 563084b0b50e5691808b4f3bdfb6a7bbdc3a883c Mon Sep 17 00:00:00 2001 From: shoo Date: Sat, 31 Aug 2024 04:03:23 +0900 Subject: [PATCH] Enhancement of readJson Support to read raw JSONValue --- voile/fs.d | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/voile/fs.d b/voile/fs.d index 737f782..96db207 100644 --- a/voile/fs.d +++ b/voile/fs.d @@ -979,7 +979,7 @@ struct FileSystem } /*************************************************************************** - * JSONファイルを書き出す + * JSONファイルを読み込む */ T readJson(T)(string filename) { @@ -991,11 +991,22 @@ struct FileSystem return deserializeFromJsonString!T(readTextImpl!false(absFilename)); } + /// ditto + T readJson(T: JSONValue)(string filename) + { + auto absFilename = absolutePath(filename); + if (!isFileImpl!false(absFilename)) + return T.init; + return parseJSON(readTextImpl!false(absFilename)); + } + /// @system unittest { auto fs = createDisposableDir("ut"); fs.writeJson!uint("a/b/test.json", 10); + auto jv = fs.readJson!JSONValue("a/b/test.json"); + assert(jv.get!int == 10); assert(fs.readJson!uint("a/b/test.json") == 10); }