Can't access for each json children after deserializing


Hey guys,

Does anyone know how to access json children inside for each loop? Tried a couple of variations but no luck so far.
Tried:
item.id.ToString
item(id).ToString
item.Item(“id”).ToString

@pink_unicorn_waif welcome to UiPath Community
What is the error?
Try with Item(“id”)

Hi @pink_unicorn_waifu

Please check this… might help you

Cheers

![Screenshot 2022-11-26 at 18.20.29|690x394]

The only thing that seemed to work was jsonOutput.Item(“id”).ToString but I started getting another error.

so the json here contains an array of products. I want to send each product ID via API Post to Airtable.

So far, nothing works

Hi @pink_unicorn_waifu

Did you change the type argument property in for each loop?

cheers

Doesn’t work, mate,

Funny enough, if I dump the contents of each currentItem ToString it shows what’s in it. However, I can’t access keys such as id … etc.

Hi @pink_unicorn_waifu

can you send the json output please that you are getting from the request?

cheers

Hi @pink_unicorn_waifu

Did you try Did you try currentItem.Value(“ID”)

cheers

Man, I really appreciate you helping me.

this is the json structure:

At step 1 I assume that the response is converted from string to object.
As step 2 I assume that the json object can be traversed to the “products” array
At step 3 I assume that I can get the id from each product in the array.

Can’t figure out where to set another type as there are no other options available.

for currentItem.Value(“ID”) i get the “error BC30574: Option strict on disallows late binding”

Thanks.

1 Like

Hi @pink_unicorn_waifu

Finally I could achieve it. So how did I do that is as follows

so first when DE-serialized we get a JObject
Then in loop we are getting a Jproperty
Then if we loop it we get a JArray
on looping Jarray we get the JObject which contains your ID
which can then be accesssed

Attaching xaml and screenshots (developed on latest 22.10 Windows project)


1st loop Type argument

2nd loop Type argument
image

3rd loop Type argument

Output
image

Input Json(Formatted to make it a string copied from the link provided):
Jsoninput.txt (10.9 KB)

Hope this helps

cheers

Thanks a lot, Anil, but I can’t find any of the settings that you described above.
Are you using Studio?

This is my screen. I’m using the web version of Studio. Even the FOR/EACH step looks different, not to mention the properties.

Is there any way to configure the web version of STUDIO?

Thanks

Hi,

It’s probably because currentItem of FoEach is automatically defined as Object type.
So, Can you try as the following sample?

First create variable products as List<JToken> type. Then assign jo("products").ToList to it.
Next, use products variable as input of ForEach

Regards,

Thanks Yoichi! Your suggestion worked like a charm. I would have never guessed it.

There are a few problems along the way that I want to point out for anyone reading this thread. The interface isn’t that intuitive unfortunately and “ToList” isn’t suggested as an option in the expression editor.

Next, if you want to set the variable (product) value and choose to select “List” from the Type dropdown, you will end up going down a very long rabbit hole to nowhere. Just leave “List” prefilled there (if it gets prefilled for you) and hope for the best.

1 Like

Hi,

As Studio Web is still preview version, there are a lot of not very good candidates etc. It might be good if you could feedback these things to UiPath guys from top-right Feedback button.

image

Regards,

1 Like

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