// 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.