Function parseJSONStream

Parses a JSON document using a lazy parser node range.

JSONParserRange!(JSONLexerRange!(Input,options,String)) parseJSONStream(LexOptions options = LexOptions.init, String, Input) (
  Input input,
  string filename = null
)
if (isInputRange!Input && (isSomeChar!(ElementType!Input) || isIntegral!(ElementType!Input)));

JSONParserRange!Input parseJSONStream(Input) (
  Input tokens
)
if (isJSONTokenInputRange!Input);

This mode parsing mode is similar to a streaming XML (StAX) parser. It can be used to parse JSON documents of unlimited size. The memory consumption grows linearly with the nesting level (about 4 bytes per level), but is independent of the number of values in the JSON document.

The resulting range of nodes is guaranteed to be ordered according to the following grammar, where uppercase terminals correspond to the node kind (See JSONParserNodeKind).

Example

import std.algorithm;

auto rng1 = parseJSONStream(`{ "a": 1, "b": [null] }`);
with (JSONParserNodeKind)
{
    assert(rng1.map!(n => n.kind).equal(
        [objectStart, key, literal, key, arrayStart, literal, arrayEnd,
        objectEnd]));
}

auto rng2 = parseJSONStream(`1 {"a": 2} null`);
with (JSONParserNodeKind)
{
    assert(rng2.map!(n => n.kind).equal(
        [literal, objectStart, key, literal, objectEnd, literal]));
}