How to read array from .json file?

{
“description”: “ReadJSON”,
“version”: “2016.2.6232.26817”,
“main”: “Main.xaml”,
“id”: “Main”,
“dependencies”: {},
“configurationOptions”: {},
“excludedData”: [
“Private:*”,
password
],
“page”:[ “1”, “2”, “3”,“4”,“5” ]
}

How I can read page into UiPath and find whether 5 is available in array. Thanks.

Hello,
Well I’m not an expert with .json files. But if you use Read Text File to store it into a string, then you can use Split functions.

For example,
text.Split({“”“page”“:”},StringSplitOptions.None)(1).Split(Environment.NewLine(0))(0) will give you [ “1”, “2”, “3”, “4”, “5” ]

Then I guess you can replace the [, ], and " with Replace function. And if you want it to be stored into an array, then split by the comma.

For example,
text.Split({“”“page”“:”},StringSplitOptions.None)(1).Split(Environment.NewLine(0))(0).Replace(“[”,“”).Replace(“]”,“”).Replace(“”“”,“”).Replace(" “,”“).Split(”,"(0))

Not sure if that’s what you need but hope it helps.

Thanks.

Another soluction would be to use Deserialize Json activity

jObject(“page”).ToString will fetch you [ “1”, “2”, “3”,“4”,“5” ]

2 Likes

Thanks. Is it not possible to get the data as array and checking whether 5 is available or not using exists collection or contains method ?

Once you get "[ “1”, “2”, “3”, “4”, “5” ] stored in a string you can use .Contains

For example,
string.Contains(“”“5"”")
or
string.Contains(“”“”+variable+“”“”)
will return True or False

you can also use .Split function to create an array.
For example,
string.Replace(" “,”“).Replace(”[“,”“).Replace(”]“,”“).Split(”,"(0))
will return an Array[of type string], and you can use a For Each with that

Thanks.

also in your case

String.Concat(jObject(“page”).ToString.Where(AddressOf Char.IsDigit)).ToArray

based on answer given by @ClaytonM in the past.

2 Likes

This might help:

Hi
Pls follow this

1 Like

Hi All,
@ClaytonM, @vvaidya, @andrzej.kniola, @karthik_bethi

I am new to UiPath API testing.Using HTTP Request I am able to print the json Response and Status successfully. But, I want to go into the json response and get first Key Value “MessageId”:“10390”. When I am trying to loop into json array. I am getting “Type JArray is not defined.” Can anyone tell me what should I do.

Json Response :

image

Thank you,
Bhaskar

I’m not entirely sure, but make sure you have imported the namespace for JArray:
image

Hi @ClaytonM,

Yes I am using the same Namespace.

I tried to reproduce the compiler error by creating a JArray inside a For each but could not get the error. It might be more helpful if you could upload a sample workflow that reproduces the compiler error.

I am using REST API provided by my company. So I cant share with you sorry :frowning:
Can you please share your workflow so that I can compare with mine.

Hi @ClaytonM please find my json file.

data.json (690 Bytes)

I think there is some problem with my “Deserialize JSON Array” activity.

jarraystuff.xaml (7.5 KB)
I literally just spent 10seconds on it adding a For each and creating a JArray variable to use inside, and got no compiler errors. But here you go.

Maybe, but you should not have any compiler errors. Once those are removed, then you can run it and figure out the rest of the problems, lol.

@Madhavi

When I am using “Deserialize JSON Array” activity then only I am getting compiler error.
If I remove “Deserialize JSON Array” activity and run the workflow with “Write Line activity” I am getting correct output. So how can I go into the json response and get correct key value “MessageId”:“10390”.

Workflow with Output:

That’s weird, cause I placed the Deserialize json Array on my end and got no compiler errors

You do have the namespace imported right by going to the Imports tab (next to Variables)?

Yes I do have namespace importer after Variables.

Follow this UiPath Tutorial For Beginners - JSON Parsing - YouTube

Is its possible to send the http response? may be there will be format issue.