Struct JSONValue

Represents a generic JSON value.

struct JSONValue ;

The JSONValue type is based on std.variant.Algebraic and as such provides the usual binary and unary operators for handling the contained raw value.

Raw values can be either null, bool, double, string, JSONValue[] or JSONValue[string].

Constructors

NameDescription
this Constructs a JSONValue from the given raw value.

Fields

NameTypeDescription
location LocationOptional location of the corresponding token in the source document.
payload taggedalgebraic.TaggedAlgebraic!(stdx.data.json.value.JSONValue.PayloadUnion)Holds the data contained in this value.

Methods

NameDescription
get Returns the raw contained value.
hasType Tests if the stored value is of a given type.
isNull Tests if the stored value is of kind Kind.null_.
opAssign Constructs a JSONValue from the given raw value.
opIndex Temporary index operations until std.variant is fixed in 2.067

Unions

NameDescription
PayloadUnion Defines the possible types contained in a JSONValue

Aliases

NameDescription
Payload Alias for a TaggedAlgebraic able to hold all possible JSON value types.

Example

Shows the basic construction and operations on JSON values.

JSONValue a = 12;
JSONValue b = 13;

assert(a == 12.0);
assert(b == 13.0);
static if (__VERSION__ >= 2067)
    assert(a + b == 25.0);

auto c = JSONValue([a, b]);
assert(c[0] == 12.0);
assert(c[1] == 13.0);
assert(c[0] == a);
assert(c[1] == b);

auto d = JSONValue(["a": a, "b": b]);
assert(d["a"] == 12.0);
assert(d["b"] == 13.0);
assert(d["a"] == a);
assert(d["b"] == b);