Select JSON Value

I have the problem that I have a json file like that:

{ “Data”: [
{ “type”: “xy”, “status”: “efas”, “surname”: “Gerhardt”, “lastname”: “Ericksen”, “companyName”: “Gerhardt Ericksen”, "
externalKeys":
[ { “eSy”: “das”, “eKy”: “14413” },
{ “eSy”: “dca”, “eKy”: “1331” },
{ “eSy”: “dca”, “eKy”: “1441” },
{ “eSy”: “dca”, “eKy”: “1551” },
{ “eSy”: “dca”, “eKy”: “1661” } ],


What I want is to select the last “eKy” value.

I used this:

Json.SelectToken(“Data[0].externalKeys[1].eKy”).ToString

for the second “eKy” but I alway want the last one.

In this case I have 5 “eKy” but maybe next time I have 2 or 6

Best regards

Hi,

Could you please try like below.

→ Use deserialize Json activity pass the input as json string and output we would get json object.

→ Now use deserialize Json Array activity pass the input as like below.

JsonObject(“externalKeys”).tostring

and output we would get the JsonArray and it is having the entries in our case in the above json we are having 5 keys. if we use the below expression we would get value as 4. so our last row key value number as 4.

JsonArraylastrowCounter= JsonArray.Count.tostring

Pass this value in your token expression to get the key value

Json.SelectToken(“Data[0].externalKeys[“+JsonArraylastrowCounter+”].eKy”).ToString

try and let me know if you face any issues. thanks.

Hey,
if you need always the last one element you can count how many their you have.
Example you can use ‘for each loop’ for “data” - like:
Convert.ToInt32(JObject(“Data”)(i)(“externalKeys”).Count)
where i is iteration (0,1,2,3 etc.)