Hi All,
Request your help in the below code, the logic is that fetch
the json data(Pool) from apidata1 and use that and search for
"pool" in sapidata2 and print the matched(pool) type from
apidata2.
Code:
import datacollector.GetLamaAssignment;
import std.stdio: writeln;
import asdf: parseJson;
import std.algorithm;
void main()
{
string[][string] sysinfo;
string apidata1 = `{"items":
[
{"name":"T01","hostname":"test01","pool":"Development"},
{"name":"T02","hostname":"test02","pool":"Quality"},
{"name":"T03","hostname":"test03","pool":"Production"}
]
}`;
string apidata2 = `{"items":
[
{"pool":"Devlopment","stack":{"type":"S"}},
{"pool":"Quality","stack":{"type":"M"}},
{"pool":"Production","stack":{"type":"L"}}
]
}`;
auto jv1 = parseJson(apidata1);
foreach(j; jv1["items"].byElement()){
string Pool = j["pool"].get!string("default");
sysinfo["Type"] ~= parseJson(apidata2)
.filter!(object => object ["items", "pool"]
.byElement
.canFind(Pool))
.each!writeln(["stack","type"]);
}
writeln(sysinfo);
}
From,
Vino.B