Json output to container

Andre Pany andre at s-e-a-p.de
Fri Oct 30 17:56:22 UTC 2020


On Friday, 30 October 2020 at 10:23:22 UTC, Vino wrote:
> Hi,
>
>   Request your help on the below code
>
> Code:
>
> 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"}
>   ]
>   }`;
>   auto data = Array!(Tuple!(string, string, string)) 
> (parseJson(apidata1)
>              .filter!(a => a.(["items"].byElement))
>              .map!(a => 
> tuple(a.(["name"].get!string("default")), 
> a.(["hostname"].get!string("default")), 
> a.(["pool"].get!string("default")))));
>   writeln(data[]);
> }
>
> From,
> Vino.B

What do you want to achieve and what is the problem with the code 
you posted?

Kind regards
Andre


More information about the Digitalmars-d-learn mailing list