Trouble selecting token from JSON Array

Good afternoon UiPath Forum,

I have successfully created a JSON array and can read the tokens. The issue is that each token now has a value under it with its own array. I am at the level I need to be in the JSON data and only want the values at the top highlighted in yellow. When I try to Assign to get the @type, id, or name, I try this but the step returns an ienumerable due to the “size” array of values below it.

ElementType = currentJToken.Values(“@type”).ToString

How can I select @type, id, and name and ignore the “size” part of the token that has its own array (or what steps are needed to deal with them)?

we only see the JObject, but not the JArray. Maybe you can share with us the complete JSON as Textfile

However, we recommend not working with the Values(… as there are more direct approaches for extractions available

Thanks very much for the fast reply @ppr

Attached is a sample file of the jarray. For each of the tokens, I’m only trying to obtain the @type, id, and name. You’ll see many examples of size, position, or padding that have their own array content under them but I don’t need those. I used Values( because I had worked with it before but I welcome a better way to select within this array. Most appreciated

Jamie
jarraysample.txt (3.6 KB)

A JArray starts with […
A JOBject starts with {
we can nest each within others

The JSON is a JArray with JObjects as items and these JOBjects also nest other JOBject for certain Properties as its value

Kindly note, that name is not present in every item e.g. id: 31

give a try at the following:

For each | TypeArgument: JOBject

currentItem = myJArray.Values(Of JObject)

Logs:
currentItem("@type").Value(Of String)
currentItem("id").Value(Of int32)
currentItem("name").Value(Of String)

IF Condition:
currentItem.ContainsKey("name")

Logoutput

1 Like

Perfect. I see what I was missing. It looked on the surface I was close, but I really wasn’t. The additional explanation you provided was vital and really helped me learn there, Peter.

Thanks very much @ppr for great feedback!!

1 Like

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