parseJSONStream

Parses a JSON document using a lazy parser node range.

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

  • list → value*
  • value → LITERAL | array | object
  • array → ARRAYSTART (value)* ARRAYEND
  • object → OBJECTSTART (KEY value)* OBJECTEND
  1. JSONParserRange!(JSONLexerRange!(Input, options, String)) parseJSONStream(Input input, string filename)
  2. JSONParserRange!Input parseJSONStream(Input tokens)
    parseJSONStream
    (
    Input
    )
    (
    Input tokens
    )

Examples

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

Meta