JSONValue.get

Undocumented in source. Be warned that the author may not have intended to support it.
  1. inout(T) get [@property getter]
  2. inout(T) get [@property getter]
    struct JSONValue
    @property inout pure @trusted
    inout(T)
    get
    (
    T : JSONValue[]
    )
    ()
  3. inout(T) get [@property getter]

Examples

import std.exception;
import std.conv;
string s =
`{
    "a": 123,
    "b": 3.1415,
    "c": "text",
    "d": true,
    "e": [1, 2, 3],
    "f": { "a": 1 },
    "g": -45,
    "h": ` ~ ulong.max.to!string ~ `,
 }`;

struct a { }

immutable json = parseJSON(s);
assert(json["a"].get!double == 123.0);
assert(json["a"].get!int == 123);
assert(json["a"].get!uint == 123);
assert(json["b"].get!double == 3.1415);
assertThrown!JSONException(json["b"].get!int);
assert(json["c"].get!string == "text");
assert(json["d"].get!bool == true);
assertNotThrown(json["e"].get!(JSONValue[]));
assertNotThrown(json["f"].get!(JSONValue[string]));
static assert(!__traits(compiles, json["a"].get!a));
assertThrown!JSONException(json["e"].get!float);
assertThrown!JSONException(json["d"].get!(JSONValue[string]));
assertThrown!JSONException(json["f"].get!(JSONValue[]));
assert(json["g"].get!int == -45);
assertThrown!ConvException(json["g"].get!uint);
assert(json["h"].get!ulong == ulong.max);
assertThrown!ConvException(json["h"].get!uint);
assertNotThrown(json["h"].get!float);

Meta