Foreach output into a multi dimensional associative array.

Vino akashvino79 at gmail.com
Mon Oct 26 19:05:04 UTC 2020


Hi All,

   Request your help on the below on how to store the output to a 
multi dimensional associative array.

Code:

import std.stdio: writeln;
import asdf: parseJson;
import std.conv: to;

void main()
{
  string[int][string] aa;
  string apidata = `{"items":
   [
     {"name":"T01","hostname":"test01","pool":"Development"}
     {"name":"T02","hostname":"test02","pool":"Quality"},
     {"name":"T03","hostname":"test03","pool":"Production"}
   ]
   }`;
  auto jv = parseJson(apidata);
   foreach(j; jv["items"].byElement()){
       aa["Name"] = j["name"].get!string("default");
        i++;
   }
   writeln(aa);
}

Expected Output
aa["Name"] = [T01, T01, T03]
aa["Hostname"] = [test01, test02, test03]
aa["Pool"] = [Development, Quality, Production]

From,
Vino.B


More information about the Digitalmars-d-learn mailing list