How to saperate json

i have below json
[
{
“id”: 311798,
“testExecKey”: “TEST81313-1323”,
“testKey”: “TEST81313-1318”,
“status”: “ON-HOLD”,
“type”: “Manual”,
“start”: “2023-06-15T08:10:39+02:00”,
“executedBy”: “rupmore”,
“defects”: [
https://e-3d-jirira2/browse/TEST81313-1330"
],
“evidences”: [],
“steps”: [],
“assignee”: “abc”,
“testEnvironments”: [],
“iterations”: []
},
{
“id”: 311799,
“testExecKey”: “TEST81313-1323”,
“testKey”: “TEST81313-1319”,
“status”: “ABORTED”,
“type”: “Manual”,
“start”: “2023-06-15T08:10:43+02:00”,
“finish”: “2023-06-15T08:10:43+02:00”,
“executedBy”: “rupmore”,
“defects”: [],
“evidences”: [],
“steps”: [
{
“status”: “TODO”,
“defects”: [],
“evidences”: []
}
],
“assignee”: “abc”,
“testEnvironments”: [],
“iterations”: []
},
{
“id”: 311800,
“testExecKey”: “TEST81313-1323”,
“testKey”: “TEST81313-1320”,
“status”: “FAIL”,
“type”: “Manual”,
“start”: “2023-06-15T08:10:36+02:00”,
“finish”: “2023-06-15T08:10:36+02:00”,
“executedBy”: “abc”,
“defects”: [],
“evidences”: [
{
“filename”: “MicrosoftTeams-image (39).png”,
“contentType”: “image/png”,
“data”: "https://e-3d-jira2.capge
ent/221611/MicrosoftTeams-image (39).png”
}
],
“steps”: [
{
“status”: “TODO”,
“defects”: ,
“evidences”:
},
{
“status”: “TODO”,
“defects”: ,
“evidences”:
}
],
“assignee”: “abc”,
“testEnvironments”: ,
“iterations”: ,
“comment”: “Action is failed for this execution and case\n”
},
{
“id”: 311801,
“testExecKey”: “TEST81313-1322”,
“testKey”: “TEST81313-1315”,
“status”: “FAIL”,
“type”: “Manual”,
“start”: “2023-06-15T08:09:37+02:00”,
“finish”: “2023-06-15T08:09:37+02:00”,
“executedBy”: “gudigoud”,
“defects”: ,
“evidences”: [
{
“filename”: “Xray_Screenshot 2023-06-15 111750.jpg”,
“contentType”: “image/jpeg”,
“data”: “https://e-3d-jira2.capgem***chment/221612/Xray_Screenshot 2023-06-15 111750.jpg”
}
],
“steps”: [
{
“status”: “TODO”,
“defects”: ,
“evidences”:
},
{
“status”: “TODO”,
“defects”: ,
“evidences”:
},
{
“status”: “TODO”,
“defects”: ,
“evidences”:
}
],
“assignee”: “abc”,
“testEnvironments”: ,
“iterations”: ,
“comment”: “Test case failed due to some defect”
}

i have above json and i need to saperate thius like belwo,
my first “testExecKey”: “TEST81313-1323” is this and second is “testExecKey”: “TEST81313-1322”,
i need data form first to below (date before start of second testextkey) means till that } brace


how can i achieve this

Hi @Mathkar_kunal

  1. Deserialize JSON Array:
  • Use the “Deserialize JSON Array” activity to convert the JSON data into a list of dictionaries. Pass the JSON data as input and create an output variable, let’s say jsonList.
  1. Separate Data:
  • Use a “For Each” loop to iterate through each item (dictionary) in the jsonList.
  • Within the loop, use the “Assign” activity to check the value of the “testExecKey” key for each item.
  • If the “testExecKey” value is different from the previous value, it means a new set of data has started for a different “testExecKey.” In this case, you can perform the desired actions with the data from the previous “testExecKey,” and then clear the variables storing the previous data.
  • Store the data for the current “testExecKey” in variables to use in the next iteration.
  1. Process the Data:
  • Within the loop, you can perform any desired actions with the data for each “testExecKey.” For example, you can create separate JSON files, process the data, or display it in the UiPath Output panel using “Write Line” activity.
  • Within the loop, use the “Assign” activity to check the value of the “testExecKey” key for each item. - how can i cehck? what to assign

can you explain a bit.
i have jsonlist , i a reading text and passing varaiable Jsontext in deserializejson array activity so for now have to variables - jsonlist and jsontext

Can you send the json file if possible

File.json (3.2 KB)

please find file

Hi @Mathkar_kunal ,

Maybe one of the approaches :

JArray.FromObject(jArr.TakeWhile(Function(x)x("testExecKey").toString.Equals("TEST81313-1323")))

Here, jArr is a variable of type JArray received from the Output of Deserialize Json Array activity and assumed is that we know the value that we need to retrieve or Keep, hence we use that value for this logic. (for your case the value TEST81313-1323 for the property textExecKey)

that 1323 value wil change everytime

@Mathkar_kunal ,

In that case , we can try with the reversal condition :

JArray.FromObject(jArr.TakeWhile(Function(x)Not x("testExecKey").toString.Equals("TEST81313-1322")))

or

JArray.FromObject(jArr.Where(Function(x)Not x("testExecKey").toString.Equals("TEST81313-1322")))

to which variable we need to assign this means what will be the datatype of that variable

any update on same please share

@Mathkar_kunal ,

It can be assigned to a JArray type of variable :

ok this need to assign inside for each?


inside this?

@Mathkar_kunal ,

You would not need a For Each activity, Just an Assign activity as mentioned.

Put a Breakpoint after Deserialize Json Array activity and check in the immediate Panel the Expression as shown in the image provided above. You should be able to get it working the same way.

1 Like

ok tested but giving whole data except 1322 for second
JArray.FromObject(jArr.Where(Function(x)Not x(“testExecKey”).toString.Equals(“TEST81313-1322”)))

@Mathkar_kunal ,

Could you also check and let us know if the other expression works ?

Also, to be precise on what is the Data needed as Output, Could you also prepare the Expected Output ? This way we can match the Outputs we get and confirm.

as i mentioned in my query i need to saperate each textexckey block start with brace and end with brace.
in between for that testkey will be present .
each testexckey may contains 1or more than one testkeys .
so need that whole testexckey flock with each testkey then i need next block for next testexckey

image

if you are not clear we can conenct on google meet if possible now

@Mathkar_kunal ,

As already mentioned, providing us with the Expected Output data in the format/form it is required, will help us collaborate together and work on it.

As we are not opposed to the one-to-one call, but seems like this could be possible once the expected output is known, we could wait for your input and also continue with the our work.

If really required, we could jump on the call, if nothing else seems to work.

Expected result 1.json (2.1 KB)
Expected result 2.json (1.2 KB)
input json data.json (3.2 KB)

please find attachments.

@Mathkar_kunal ,

Apologies as I could not get the separate term intially in your Query. The concentration was more towards the last line of the query.

Even for the Expected Results provided by you, we could use the Same Expression :

To retrieve results other than 1322 :

jArr1 = JArray.FromObject(jArr.Where(Function(x)Not x("testExecKey").toString.Equals("TEST81313-1322")))

To retrieve results with 1322 :

jArr2 = JArray.FromObject(jArr.Where(Function(x)x("testExecKey").toString.Equals("TEST81313-1322")))

Two variables are used to store the results as you would need it in that fashion.

1 Like

Taking a look at these…