On Sunday, 25 October 2020 at 08:22:06 UTC, 9il wrote:
On Sunday, 25 October 2020 at 06:05:27 UTC, Vino wrote:
Hi All,

Currently we are testing various json module such as "std.json, std_data_json, vibe.data.json and asdf", the below code works perfectely while use "std_data_json or vibe.data.json" but not working as expected when we use "asdf" and throwing the below error, hence request your help on the same.

[...]

Hi Vino,

byElement should be used here for ASDF.

foreach(j; jv["items"].byElement)

http://asdf.libmir.org/asdf_asdf.html#.Asdf.byElement

Hi All,

Thank you for your help, and now need your suggestion as the below code is working and it also prints an additional value which is not expected, so request your help on how to avoid the additional value,

Code:
import std.stdio: writeln;
import asdf: parseJson;
import std.conv: to;
import std.range: takeExactly;
import std.array: split;

void main()
{
 string apidata = `{"items":
  [
    {"name":"T01","hostname":"test01","pool":"Development","type":
    [{"Value":"D,d...@dev.com,DEV"},{"Value":"000"}]},
    {"name":"T02","hostname":"test02","pool":"Quality","type":
    [{"Value":"Q,q...@qas.com,QAS"},{"Value":"100"}]},
    {"name":"T03","hostname":"test03","pool":"Production","type":
    [{"Value":"P,p...@prd.com,PRD"},{"Value":"100"}]}
  ]
}`;
 auto jv = parseJson(apidata);
 foreach(j; jv["items"].byElement()){
    foreach(i; j["type"].byElement().takeExactly(1)) {
       writeln(i["Value"].get!string("default").split(",")[1]);
    }
 }
}

Output:
d...@dev.com
q...@qas.com
p...@prd.com
[]   // additional value which is not expected

From,
Vino.B

Reply via email to