How to get specific values form json

hello,

please check below json

{

“testExecutionKey”: “P003106-4272”,
“tests”: [
{
“status”: “PASS”,
“testKey”: “P003106-4264”,
“start”: “2022-11-02T08:54:16+01:00”,
“finish”: “2022-11-03T10:08:09+01:00”,
“executedBy”: “abc”,
“defects”: ,
“evidences”: ,
“steps”: [
{
“status”: “PASS”,
“defects”: ,
“evidences”:
},
{
“status”: “PASS”,
“defects”: ,
“evidences”: [
{
“filename”: “TE4272_TC4264_1.png”,
“contentType”: “image/png”,
“data”: “TE4272_TC4264_1.png”
}
]
},

{
  "status": "PASS",
  "defects": [],
  "evidences": [
    {
      "filename": "TE4272_TC4264_5.png",
      "contentType": "image/png",
      "data": "TE4272_TC4264_5.png"
    },
    {
      "filename": "TE4272_TC4264_6.png",
      "contentType": "image/png",
      "data": "TE4272_TC4264_6.png"
    },
    {
      "filename": "TE4272_TC4264_7.png",
      "contentType": "image/png",
      "data": "TE4272_TC4264_7.png"
    }
  ]
},

{
  "status": "PASS",
  "defects": [],
  "evidences": []
}

],
“assignee”: “abc”,
“testEnvironments”: ,
“iterations”: ,
“comment”: “null”
}

           ]

}

I need saperate attachment from all steps and write in excel which step number , attachment name like below
in above json under steps -
1]first step doesnt contains any attachment so need to write step 1 , no attahment
2]second step contains 1 attachment under evidence - data which TE4272_TC4264_1.png so step 2 , attachment - TE4272_TC4264_1.png
3] step 3 contains 3 attachments under evidence - data which are TE4272_TC4264_5.png , TE4272_TC4264_6.png,TE4272_TC4264_7.png so need to write same in excel like above
4] step 4 again doest contains any attachment

please let me know how can i saperate attachment for each Step
excdl part i can manage just update me how can i scrap one by one
@ppr now json is correct
help me on same
jsonT.txt (1.3 KB)

Hi,

Can you try the following sample?

Sample
Sample20240125-6.zip (3.8 KB)

Regards,

1 Like

For demo and learning purposes find a LINQ approach


dtData =

(From tidx In Enumerable.Range( 0, myJObject.SelectTokens("..tests").Count )
From sidx In  Enumerable.Range( 0, myJObject("tests")(tidx)("steps").Count )
Let dlr = myJObject("tests")(tidx)("steps")(sidx).SelectTokens("..data").Select( Function (d) d.ToString ).toArray
Let dle = If (dlr.Count.Equals(0), {"No Data"}, dlr)
From ra In dle.Select( Function (dv,didx) New Object() {tidx +1, sidx+1, didx + 1, dv} )
Select r = dtData.Rows.Add(ra)).CopyToDataTable

grafik