Can I modify data inside a JArray?

Hello,

I am pulling an item off a queue, That item has a few string fields, and one of them is serialized with Json. For that field (which was initially a list of dictionaries), I want to add a new key and value in the dictionary for some of the list elements, and then serialize it back to JSON and put it on another queue.

The question is: after I deserialize and get a JArray object - can I modify the respective JToken objects inside the array by adding a new JProperty ? Or do I have to further convert the JArray to a list of dictionaries, modify the dictionary and then serialize back ?

Currently I am trying the following approach, and I get the error message

“Assign the error text to the JToken: Exception has been thrown by the target of an invocation.”

the last assign is
ja_listOfItemsDeserialized(int_counter) = New JProperty(“itemErrorText”,str_itemErrorText)

Thank you,
Gabi.

I found the solution. This worked (in an assign):

ja_listOfItemsDeserialized(int_counter)(“itemErrorText”) = str_itemErrorText

this updated the JToken inside the JArray, and then I could just take the whole JArray and serialize it back.

1 Like

I have recorded a short video on the solution - hope it is useful for somebody.

1 Like

Thank you @gabi_verzea for providing enough info and helping the fellow folks :slight_smile:

1 Like

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