21 lines
350 B
D
21 lines
350 B
D
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;
|
|
}
|