Initial AP objects implementation
This commit is contained in:
20
source/util.d
Normal file
20
source/util.d
Normal file
@@ -0,0 +1,20 @@
|
||||
module util;
|
||||
|
||||
import std.format;
|
||||
import std.json;
|
||||
|
||||
JSONValue requiredKey(string key)(JSONValue val) {
|
||||
const(JSONValue)* j = key in val;
|
||||
|
||||
if (j)
|
||||
return *j;
|
||||
|
||||
throw new Exception(format("Key %s not found in json", key));
|
||||
}
|
||||
|
||||
T checkKey(T)(JSONValue val, string key) {
|
||||
if (JSONValue* j = key in val)
|
||||
return (*j).get!T;
|
||||
|
||||
return T.init;
|
||||
}
|
||||
Reference in New Issue
Block a user