Remove objects from jArray inside jObject

Hi

I have a jObject with nested jArray where I need to remove (or keep) specific indexes within.

See example JSON below.

{
    "key1": "abc",
    "key2": "def"
	"forms": [
		{
			"key1": "abc",
			"key2": "def
		},
		{
			"key1": "abc",
			"key2": "def
		},
		{
			"key1": "abc",
			"key2": "def
		},
	]
	"key3": "xyz"
}

I need to keep only one of the entries inside the “forms” jArray - eg. remove index 0 and 2, so the middle one is kept.
The overall structure should remain, but simply remove specific entries from a jArray.

See image for reference.

I know that you can remove specific keys/values from a jArray by using the Invoke Code activity, but I am unsure of how it should be configured, to achieve the desired format.

Example:

@ppr

Regards
Soren

as far as we have understood you want to remove entries form the JArray, which are JObjects.

So there are two strategies:

  • removing items by index (indexes ordered DESC) and the removal one by one

  • OR: replace the JArray by a modified JArray, which kept only the needed items

UPD-1: Docu Linke Added

1 Like

Hahah perfect :grin: :grin:
Of course I was missing the Reverse to make sure the indexes wouldn’t change when the iteration removes entries.

Thanks @ppr :folded_hands:

I ended up with this code:

Regards
Soren

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