Provides various means for parsing JSON documents.
This module contains two different parser implementations. The first
implementation returns a single JSON document in the form of a
JSONValue, while the second implementation returns a stream
of nodes. The stream based parser is particularly useful for
deserializing with few allocations or for processing large documents.
Example
import std.algorithm : equal, map;
// Parse a JSON string to a single value
JSONValue value = toJSONValue(`{"name": "D", "kind": "language"}`);
// Parse a JSON string to a node stream
auto nodes = parseJSONStream(`{"name": "D", "kind": "language"}`);
with (JSONParserNodeKind) {
assert(nodes.map!(n => n.kind).equal(
[objectStart, key, literal, key, literal, objectEnd]));
}
// Parse a list of tokens instead of a string
auto tokens = lexJSON(`{"name": "D", "kind": "language"}`);
JSONValue value2 = toJSONValue(tokens);
assert(value == value2);