How to read array from .json file?

json

#1

{
“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.


#2

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.


#3

Another soluction would be to use Deserialize Json activity

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


#4

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 ?


#5

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.


#6

also in your case

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

based on answer given by @ClaytonM in the past.


#7

This might help:


#8

Hi
Pls follow this