Module stdx.data.json

Package import for the whole std.data.json package.

Synopsis

// Parse a JSON string
JSONValue value = toJSONValue(`{"name": "D", "kind": "language"}`);
assert(value["name"] == "D");
assert(value["kind"] == "language");

// Convert a value to a formatted JSON string
assert(value.toJSON() ==
`{
    "name": "D",
    "kind": "language"
}`);

// Convert a value back to a JSON string
assert(value.toJSON(GeneratorOptions.compact) == `{"name":"D","kind":"language"}`);

// Lex a JSON string into a lazy range of tokens
auto tokens = lexJSON(`{"name": "D", "kind": "language"}`);
with (JSONToken.Kind) {
    assert(tokens.map!(t => t.kind).equal(
        [objectStart, string, colon, string, comma,
        string, colon, string, objectEnd]));
}

// Parse the tokens to a value
JSONValue value2 = toJSONValue(tokens);
assert(value2 == value);

// Parse the tokens to a JSON node stream
auto nodes = parseJSONStream(tokens);
with (JSONParserNode.Kind) {
    assert(nodes.map!(n => n.kind).equal(
        [objectStart, key, literal, key, literal, objectEnd]));
}