Athul_AK
(Athul AK)
April 3, 2023, 11:27am
1
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”}}]
Gokul001
(Gokul Balaji)
April 3, 2023, 11:32am
2
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
Hi, I’m trying to deserialize a string that contains JSON. It contains multiple entries.
Some context: I’m taking text from the body of an email (there’s plaintext JSON at the end of it) for survey results and outputting it into excel. But I’ve been unable to separate the questions and answers because of how it’s formatted.
For example:
{“question”:“Reference Number”,“answer”:“847564592”},{“question”:“Timestamp”,“answer”:“Mon, 16 Mar 2020 02:10:46 PM”},{“question”:“Name”,“answer”:“Alex Bob Jo…
Regards
Gokul
1 Like
Anil_G
(Anil Gorthi)
April 3, 2023, 11:45am
3
@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
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
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
system
(system)
Closed
April 6, 2023, 11:54am
5
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.