Hawkman
(Hakon)
September 20, 2023, 9:03am
1
Hello I have a complex JArray which i want to remove an array and add an object. I have spent 2 days googling trying to learn how to do it, but it seems much more difficult than handling a xml file.
My Json looks like this:
[
{
“wfTaskActions”: [
{
“description”: “Godkjenne”,
“wfTaskAction”: “AP”,
“requiresComment”: false
},
{
“description”: “Avvise”,
“wfTaskAction”: “RJ”,
“requiresComment”: true
}
],
“isParked”: false,
“voucherNo”: 900061930,
“sequenceNo”: 1,
…
Deserialized to JsonArray it looks like this:
JArray(2)
{
JObject(21)
{
JProperty(1)
{
JArray(2)
{
JObject(3)
{
JProperty(1)
{
[Godkjenne]
},
JProperty(1)
{
[AP]
},
JProperty(1)
{
[False]
}
},
JObject(3)
{
JProperty(1)
{
[Avvise]
},
JProperty(1)
{
[RJ]
},
JProperty(1)
{
[True]
}
}
}
},
JProperty(1)
{
[False]
},
JProperty(1)
{
[900061930]
The Json cointaing 2 main Arrays (2 accounting rows on an invoice)
I want to remove the first JObject “wfTaskActions” containing the 2 arrays inside, in both main arrays
I want to add a JObject “wfTaskAction”:“AP”, before the JObject “isParked”: false, in both main arrays
How can i achive this?
ppr
(Peter)
September 20, 2023, 9:21am
2
may we ask you to share the JSON as Text file or at least user the </>
Format from editor and share with us the output from YourJObjectVar.toString
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum
It would also help us when you share with us a sample of the expected final result. Thanks for support
ppr
(Peter)
September 20, 2023, 9:44am
3
Also have a look at the below simplified sample and some statements
before:
Using invoke Code / invoke Method for calling sub (subroutines, void methods, methods without a return value and not usable within an assign activity)
Result:
A quick dirty line also could look like this (used within Invoke Code)
io_JArray(0).Value(Of JObject).Property("wfTaskActions").Replace(new JProperty("wfTaskAction","AP")
Hawkman
(Hakon)
September 20, 2023, 12:44pm
4
Hello. This was exactly what I was looking for, thank you.
Also thanks for the tip about using the “Immediate” panel during debugging, never used that before, but I see now it has a very high usecase
Hawkman
(Hakon)
September 20, 2023, 12:52pm
5
Another question:
My invoices can contain multiple accounting rows (unknown number) The number of “main arrays” in the JArray can vary. Therefor the Remove and Add lines of code need to be done for each accounting row (array). My solution was assigning index = JArray.Count and then doing a while loop with condition index > 0. And then assigning a new idx = index-1 to since array indexes start at zero (0).
Maybe there is another agile way for invoking the codes for all the arrays the JArray might have ?
ppr
(Peter)
September 20, 2023, 12:54pm
6
Hawkman:
Another question:
Let’s get scoped 1 topic = 1 case, so thers can faster solutions for their similar case
Just create a new Topic and we will pick you up from there. Thanks
system
(system)
Closed
September 23, 2023, 12:54pm
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.