fromJSON

Extract a value from a json object by its key.

Throws if json is not of JSON_TYPE.OBJECT. Return defaultVal if the key does not exist.

Parameters

T

Target type. can be any primitive/builtin D type, or any user-defined type using the JsonizeMe mixin.

json
Type: JSONValue

JSONValue to deserialize.

key
Type: string

key of desired value within the object.

defaultVal
Type: T

value to return if key is not found

options

configures the deserialization behavior.

Examples

Substitute default values when keys aren't present.

auto aa = ["a": 1, "b": 2];
auto json = JSONValue(aa);
assert(json.fromJSON!int("a", 7) == 1);
assert(json.fromJSON!int("c", 7) == 7);

Meta