27 lines
464 B
D
27 lines
464 B
D
module util;
|
|
|
|
import std.format;
|
|
import std.json;
|
|
|
|
void optional(T)(ref JSONValue val, string key, ref T receiver) {
|
|
const(JSONValue)* p = key in val;
|
|
|
|
if (p == null)
|
|
return;
|
|
|
|
static if (is(JSONValue == T))
|
|
receiver = *p;
|
|
else
|
|
receiver = (*p).get!T;
|
|
}
|
|
|
|
T optional(T)(ref JSONValue val, string key) {
|
|
T t;
|
|
optional(val, key, t);
|
|
return t;
|
|
}
|
|
|
|
void required(T)(ref JSONValue val, string key, ref T receiver) {
|
|
receiver = val[key].get!T;
|
|
}
|