parseJson

Parses json value

  1. Asdf parseJson(Chunks chunks, size_t initLength)
  2. Asdf parseJson(char[] str, Allocator allocator)
  3. Asdf parseJson(char[] str)
    parseJson
    (
    Flag!"includingNewLine" includingNewLine = Yes.includingNewLine
    Flag!"spaces" spaces = Yes.spaces
    Flag!"assumeValid" assumeValid = No.assumeValid
    )
    (
    in char[] str
    )

Parameters

str char[]

input string

Return Value

Type: Asdf

ASDF value

Examples

assert(`{"ak": {"sub": "subval"} }`.parseJson["ak", "sub"] == "subval");
import std.experimental.allocator.mallocator: Mallocator;
import std.experimental.allocator.showcase: StackFront;

StackFront!(1024, Mallocator) allocator;
auto json = parseJson(`{"ak": {"sub": "subval"} }`, allocator);
assert(json["ak", "sub"] == "subval");

Faulty location

import asdf;
try
{
    auto data = `[1, 2, ]`.parseJson;
}
catch(AsdfSerdeException e)
{
    import std.conv;
    /// zero based index
    assert(e.location == 7);
    return;
}
assert(0);

Meta