JSONValue

* Represents a generic JSON value. * * 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

this
this(T value, Location loc)

Constructs a JSONValue from the given raw value.

Alias This

payload

Members

Aliases

Payload
alias Payload = TaggedAlgebraic!PayloadUnion

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

Functions

get
inout(T) get()

Returns the raw contained value.

hasType
bool hasType()

Tests if the stored value is of a given type.

isNull
bool isNull()

Tests if the stored value is of kind Kind.null_.

opAssign
void opAssign(T value)

Constructs a JSONValue from the given raw value.

opEquals
bool opEquals(inout(T) other)

Enables equality comparisons.

Unions

PayloadUnion
union PayloadUnion

Defines the possible types contained in a JSONValue

Variables

location
Location location;

Optional location of the corresponding token in the source document.

payload
Payload payload;

Holds the data contained in this value.

Examples

Shows the basic construction and operations on JSON values.

JSONValue a = 12;
JSONValue b = 13;

assert(a == 12.0);
assert(b == 13.0);
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);

Meta