parseJson

Parses json value

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

Parameters

str char[]

input string

allocator Allocator

(optional) memory allocator

Return Value

Type: Asdf

ASDF value

Examples

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);
assert(`{"ak": {"sub": "subval"} }`.parseJson["ak", "sub"] == "subval");

Meta