On Friday, 30 October 2020 at 19:07:20 UTC, Vino wrote:

Requirement: parse the json string and store the output to a container.

From,
Vino.B

Here's a working version of the code from your original post:

import asdf : parseJson;
import std.algorithm;
import std.container.array;
import std.stdio : writeln;
import std.typecons : Tuple, tuple;

void main()
{
    string apidata1 = `{"items": [
        {"name":"T01","hostname":"test01","pool":"Development"},
        {"name":"T02","hostname":"test02","pool":"Quality"},
        {"name":"T03","hostname":"test03","pool":"Production"}
        ]}`;

        Array!(Tuple!(string, string, string)) data =
                parseJson(apidata1)["items"]
            .byElement
            .map!(item => tuple(
                item["name"].get!string("default"),
                item["hostname"].get!string("default"),
                item["pool"].get!string("default")
            ));

    writeln(data[]);
}

Reply via email to