Module stdx.data.json.parser

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);

Functions

NameDescription
parseJSONStream(input, filename) Parses a JSON document using a lazy parser node range.
parseJSONValue(input, filename) Consumes a single JSON value from the input range and returns the result as a JSONValue.
parseJSONValue(tokens) Parses a stream of JSON tokens and returns the result as a JSONValue.
readArray(nodes, del) Reads an array and issues a callback for each entry.
readArray(nodes) Reads an array and returns a lazy range of parser node ranges.
readBool(nodes) Reads a single double value.
readDouble(nodes) Reads a single double value.
readObject(nodes, del) Reads an object and issues a callback for each field.
readString(nodes) Reads a single double value.
skipToKey(nodes, key) Skips all entries in an object until a certain key is reached.
skipValue(nodes) Skips a single JSON value in a parser stream.
toJSONValue(input, filename) Parses a JSON string or token range and returns the result as a JSONValue.

Structs

NameDescription
JSONParserNode Represents a single node of a JSON parse tree.
JSONParserRange Lazy input range of JSON parser nodes.

Enums

NameDescription
JSONParserNodeKind Identifies the kind of a parser node.

Manifest constants

NameTypeDescription
isJSONParserNodeInputRange Tests if a given type is an input range of JSONParserNode.
isJSONTokenInputRange Tests if a given type is an input range of JSONToken.