How can I delete an parent node based on a child condition?

Hi all,

I’m having struggles realizing something in Alumio and I am hoping someone has a handy tip for this.

I am trying to remove a parent node based on a child condition.
Here is my example data:

"data" : [
  0:{
    "check" : "good",
    "data" : "more data"
  }
  1:{
    "check" : "bad",
    "data" : "more data"
  }
  2:{
    "check" : "good",
    "data" : "more data"
  }
]

I want to delete node with where the value of check == bad.
So in this case node 1 should be removed.

An PHP equivalent would be:

<?php
	$array = [
		0 => [
			"check" => "good",
			"data"  => "more data"
		],
		1 => [
			"check" => "bad",
			"data"  => "more data"
		],
		2 => [
			"check" => "good",
			"data"  => "more data"
		]
	];
	
	foreach($array as $key => $value){
		if($value['check'] == "bad"){
			unset($array[$key]);
		}
	}
	
	print_r($array);
?>

Results:

Array
(
    [0] => Array
        (
            [check] => good
            [data] => more data
        )

    [2] => Array
        (
            [check] => good
            [data] => more data
        )

)

It looks so trivial to do, but I cannot seem to find a way to do this in Alumio.
I must be overlooking something that can do this trick.
Anyone that has pointers in this case?

Hi Rick!

Just played around with this and i think i have a solution for you.

Output looks like this.
You can just filter “data” so you are left with “newData”

I hope this helps!

1 Like

Hi mko!

Thanks for the quick response, your solution look great but I do not like to compromise on the explicitly of the check.
In this case if another key happens to contain the work “bad” I would filter that out as well, which I do not want to happen.

But great way of thinking, I was trying things with the filter options forgetting that copy/move using a pattern is available in these cases as well.

Ah yes!

That makes sense, then i think this will do the trick

Output:
image

3 Likes

Ah yes, just what I needed indeed.
Thank you for the solution!

I should really try to do more with JMESPath, I keep forgetting that this is an option within Alumio as well.