@Matthias BlommeSorry it took so long to get back to you on this, I didn't see it right away.
I looked at your examples and I'm providing an updated PI for you to look at. I wouldn't use the loop example you had, because I really, REALLY, don't like using CARDINALITY. It's a very expensive operation and that only gets worse as the size of the array increases.
The fastest way is to delete the array and recreate it. You were close on your attempt, but you were missing the IDENTITY clause, which would make it an array, rather than an empty element. I have provided a different looping construct for you to consider, if you still want to go that route.
I also do recommend creating the DOMAIN in the Environment space, if you want to keep the formatting, especially important for XML with Attributes, but I do that for all DOMAINS to make sure I'm not losing anything.
--New Test - loop
WHILE EXISTS(rTest3.array1.Item[]) DO
DELETE FIELD rTest3.array1.Item[<];
END WHILE;
--New Test - fastest
SET rTest4.array1 = null;
CREATE FIELD rTest4.array1 IDENTITY(JSON.Array) array1;
------------------------------
James E. (Jim) Berube
Technical Account Manager (TAM) - Specialist, IBM Expertise Connect, IBM Expert Labs
IBM Software
------------------------------
Original Message:
Sent: Tue May 10, 2022 09:29 AM
From: Matthias Blomme
Subject: Deleting full array from the message tree
Is there a proper way to delete the contents of an array from the message tree while still keeping the array field?
Let's assume that copying everything except the array from input to output is not an option.
What is the most efficient way to go from this
{ "field1": "content1", "field2": "content2", "array1": ["arrayContent1", "arrayContent2", "arrayContent3"], "field3": "content3"}
To this
{ "field1": "content1", "field2": "content2", "array1": "", "field3": "content3"}
I've tried setting it to null, deleting the field and creating a new field over it all to now avail.
Looping over the array and deleting the contents seems to be the easiest way except for completly deleting it and then creating it again as a sibling of field2.
I've attached a PI with some test code I tried.
I'm curious if there is a proper way of doing this that we have missed.
------------------------------
Regards
Matthias Blomme
------------------------------