Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

asdf.jsonparser

Json Parser
Authors:
Ilya Yaroshenko
License:
MIT
  • Asdf parseJson(Flag!"includingNewLine" includingNewLine = Yes.includingNewLine, Flag!"spaces" spaces = Yes.spaces, Chunks)(Chunks chunks, size_t initLength = 32)
    if (is(ElementType!Chunks : const(ubyte)[]));
    Parses json value
    Parameters:
    Chunks chunksinput range composed of elements type of const(ubyte)[]. chunks can use the same buffer for each chunk.
    size_t initLengthinitial output buffer length. Minimal value equals 32.
    Returns:
    ASDF value
    Examples:
    import std.range: chunks;
    auto text = cast(const ubyte[])`true `;
    auto ch = text.chunks(3);
    assert(ch.parseJson(32).data == [1]);
    
  • Asdf parseJson(Flag!"includingNewLine" includingNewLine = Yes.includingNewLine, Flag!"spaces" spaces = Yes.spaces, Flag!"assumeValid" assumeValid = No.assumeValid, Allocator)(in char[] str, Allocator allocator);

    Asdf parseJson(Flag!"includingNewLine" includingNewLine = Yes.includingNewLine, Flag!"spaces" spaces = Yes.spaces, Flag!"assumeValid" assumeValid = No.assumeValid)(in char[] str);
    Parses json value
    Parameters:
    char[] strinput string
    Allocator allocator(optional) memory allocator
    Returns:
    ASDF value
    Examples:
    assert(`{"ak": {"sub": "subval"} }`.parseJson["ak", "sub"] == "subval");
    
  • auto parseJsonByLine(Flag!"spaces" spaces = Yes.spaces, Flag!"throwOnInvalidLines" throwOnInvalidLines = No.throwOnInvalidLines, Input)(Input input);
    Parses JSON value in each line from a Range of buffers.
    Parameters:
    spacesadds support for spaces beetwen json tokens. Default value is Yes.
    throwOnInvalidLinesthrows an AsdfException on invalid lines if Yes and ignore invalid lines if No. Default value is No.
    Input inputinput range composed of elements type of const(ubyte)[] or string / const(char)[]. chunks can use the same buffer for each chunk.
    Returns:
    Input range composed of ASDF values. Each value uses the same internal buffer.
    Examples:
    import asdf.jsonparser;
    import std.range: chunks;
    auto text = cast(const ubyte[])"\t true \r\r\n false\t";
    auto values = text.chunks(3).parseJsonByLine;
    assert(values.front.data == [1]);
    values.popFront;
    assert(values.front.data == [2]);
    values.popFront;
    assert(values.empty);
    
    Examples:
    import std.conv;
    import std.algorithm : map;
    import std.range : array;
    string text =  "\t " ~ `{"key": "a"}` ~ "\r\r\n" ~ `{"key2": "b"}`;
    auto values = text.parseJsonByLine();
    assert( values.front["key"] == "a");
    values.popFront;
    assert( values.front["key2"] == "b");
    values.popFront;
    
  • struct JsonParser(bool includingNewLine, bool hasSpaces, bool assumeValid, Allocator, Input = const(ubyte)[]);