Json output to container

Vino akashvino79 at gmail.com
Fri Oct 30 10:23:22 UTC 2020


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


More information about the Digitalmars-d-learn mailing list