Get individual item from Json string

Hi Team, My requirement is to get individual items from the below shown JSON string using Studio activities.

[{“Date”: {“S”: “15/04/23”}, “id”: {“S”: “13”}, “Name”: {“S”: “Arjun”}}, {“Salary”: {“S”: “10000”}, “id”: {“S”: “10”}, “Date”: {“S”: “13/04/23”}, “Name”: {“S”: “Loozi”}}]

Hi @Athul_AK

you can use the following assign activities:

• To get Date which is of data type string - jsonObjectData("Date").ToString

• To get Name which is again of datatype string - jsonObjectData.Item("Name").ToString

• To get id which is of type integer - CInt(jsonObjectData.Item("id"))

You can also use Deserialize JSON activity with Type Argument as Datatable. Supply a Datatable to the Output parameter of Json Deserialize

Check out the thread

Regards
Gokul

1 Like

@Athul_AK

I see it is a jarray…

So first use Deserialize json activity and then change the type argument to JArray(Default is JObject)

Then as below you can access each…to access each set of jArray items you need to use counter starting from 0 …and then to access values inside them use the key for those values. Here jarr is the output of Desrialize Json

jarr(1)("Name")("S") - for the second item name
jarr(0)("Date")("S") - for the first item date

image

And also Is ee salary is not present in first set and you might get exception if you use …so you can first check if it is present using IsNothing(jarr(0)("Salary")). This can be applied for any key you want to check for existance…this returns true if not present else returns false

image

Hope this helps

cheers

1 Like

Hi @Athul_AK ,

Use Deserialize JSON Array activity (UiPath.WebAPI.Activities) to deserialise the given Json Array.

Date1 = deserialiseOutput(0)(“Date”)(“S”).ToString
Name1 = deserialiseOutput(0)(“Name”)(“S”).ToString
Salary1 = deserialiseOutput(0)(“Salary”)(“S”).ToString
Id1 = deserialiseOutput(0)(“Id”)(“S”).ToString

Date2 = deserialiseOutput(1)(“Date”)(“S”).ToString
Name2 = deserialiseOutput(1)(“Name”)(“S”).ToString
Salary2 = deserialiseOutput(1)(“Salary”)(“S”).ToString
Id2 = deserialiseOutput(1)(“Id”)(“S”).ToString

It works, i have tested.
Hope it helps.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.