Module stdx.data.json.lexer

Provides JSON lexing facilities.

Synopsis

// Lex a JSON string into a lazy range of tokens
auto tokens = lexJSON(`{"name": "Peter", "age": 42}`);

with (JSONToken) {
    assert(tokens.map!(t => t.kind).equal(
        [Kind.objectStart, Kind.string, Kind.colon, Kind.string, Kind.comma,
        Kind.string, Kind.colon, Kind.number, Kind.objectEnd]));
}

// Get detailed information
tokens.popFront(); // skip the '{'
assert(tokens.front.string == "name");
tokens.popFront(); // skip "name"
tokens.popFront(); // skip the ':'
assert(tokens.front.string == "Peter");
assert(tokens.front.location.line == 0);
assert(tokens.front.location.column == 9);

Credits

Support for escaped UTF-16 surrogates was contributed to the original vibe.d JSON module by Etienne Cimon. The number parsing code is based on the version contained in Andrei Alexandrescu's "std.jgrandson" module draft.

Functions

NameDescription
lexJSON(input, filename) Returns a lazy range of tokens corresponding to the given JSON input string.

Structs

NameDescription
JSONLexerRange A lazy input range of JSON tokens.
JSONNumber Represents a JSON number literal with lazy conversion.
JSONString Represents a JSON string literal with lazy (un)escaping.
JSONToken A low-level JSON token as returned by JSONLexer.

Enums

NameDescription
JSONTokenKind Identifies the kind of a JSON token.
LexOptions Flags for configuring the JSON lexer.