Parsing JSON file that contains children of Children Error

I’m trying to Parse a JSON file which has children of children but I’m getting the below error. Any help would be greatly appreciated.

Error = For Each: Cannot cast Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JToken.

Not sure where JProperty is coming from…

Main.xaml (37.3 KB)

@Waterfowl_Waterfowl_hunte

As per error looks like what you used in assign is what you need to use in assign…but you are using selecttokens for a jproperty type which is failing

Cheers

Sometimes caches are hanging:

go to the for each

  • delete and retype the statement within the IN field
  • cross check afterwards the typeargument

we prototyped it with a dummy json (as we cannot rely to yours) and it was returning datatype (JObject)

grafik

Thank you for the reply,

*I deleted and retyped the statement with in the IN filed as you suggested.

  • Im sorry but i am fairly new to UiPath and coding in general so im not 100% sure what “cross check afterwards the typeargument” means. if you could give me some more details i would appreciate it.

i ran the bot and now i’m receiving a slightly new error. not sure if this is because i didnt know how to cross check type arguments.

New Error - For Each: Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.

I also provided the JSON in case it could help.
json.txt (2.6 KB)

please tell us

  • which version of UiPath.WebApi.Activities is referenced within your project
    grafik
    feel free to upgrade to newer versions, when not using the latest one

And

  • Version of UiPath.System.Activities

In additon:

  • we noticed the change of nwa to line_items
  • also correct to Values(Of JObject) ← s for Plural

So looks like im using versions

*UiPath.WebAPI.activties - 1.16.2 (i think newer then whats in your screen shot).
*UiPath.System.Activities - 20.10.6 (i think older) would you recommend me upgrading?

Im not sure this is correct. i didnt make any changes between nwa and lineitem. i double checked the screen shots. please correct me if im wrong. the outer ForEach is line item and the inner ForEach is nwa

At least correct Value(Of…= to Values(Of …)

old screenshot:
grafik

new sceenshot (which is also matching with your JSON Sample)
grafik

Shoot, not sure how that change happened. I changed it back to item.SelectTokens(“nwa”).Values(Of Jobject)

Now i’m getting the ‘For Each: Cannot cast Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JToken’ error

We suggest to understand more the structure of the json

 "line_items": [
    {

line_items is a property of your JObject and its value is JArray with item(s) of JObject

So we loop with
Json2("line_items").Values(Of JObject) ← Values
s due Plural as an JArray can have multiple items

 "nwa": {
        "network": "100001745575",
        "activity": "0020",
        "name": "63-1W63-B-1-5 SECURITY FEATURES"
      },

nwa is a property of your looped JObject (loop variable name: item) and its value is a JObject.
So nothing to loop, we access directly by
item(“nwa”)(“network”).Value(Of String)
item(“nwa”)(“activity”).Value(Of String)

Thank you for all your help. i have to log off for the day to take the kids to sports. I will take a look at this tonight or over the weekend talk with you on Monday. I appreciate your help and patience.

will result to:
grafik

Good Morning,

I replicated your sequence. but im getting a “Option Strict On Disallows late Binding” error. i have been trying different things for about an hour to remove the error with no joy.

I did try .ToString and not .value(of String) but received the same error

Any Thoughts?

We told:

And did show:

So:
grafik

I owe you a beer sir. Thank you for your time and patience. I have learned a lot in this conversation.

Perfect so we can close the topic by marking the helping answer:
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

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