asdf get first value from a json string.

Vino akashvino79 at gmail.com
Sun Nov 8 16:30:40 UTC 2020


Hi All,

    Request your help on how to get the first value of "type" from 
the below json, the expected output required is as below,

{"characteristicValue":"TT,TT at dev.com,DEV"}

output1: TT
output2: TT at dev.com

Code:

/+dub.sdl:
dependency "asdf" version="~>0.6.6"
+/
import std;
import asdf;

void main()
{
  string data = `{"items":[{
			  "hostname":"test01",
			  "type":[
			          {"characteristicValue":"TT,TT at dev.com,DEV"},
                                   {"characteristicValue":"000"}
		]}]}`;

  foreach (ref j; parseJson(data)["items"].byElement()) {
     writeln(j["type"]) ;
  }
}

From
Vino.B


More information about the Digitalmars-d-learn mailing list