%dw 2.0
var dropThese = [
{"type" : "secondary", "space" : "rgb"},
{"type" : "primary", "space" : "cmyk"}
]
output application/json
---
payload filter (not (dropThese contains {"type": $."type", "space": $."space"}))
Remove Objects Containing Specified Key-Value Pairs
This DataWeave example removes all objects that contain a set of key-value pairs from an array of objects.
This example uses the following functions:
-
filteriterates over the objects within the input array to return an array with the objects that returntrueas the result of an expression. Each object in the input array contains a set of key-value pairs. The expression uses thecontainsfunction and thenotoperator. -
containsidentifies the key-value pairs specified in thedropThesevariable. This variable is an array of objects containing the key-value pairs to remove.notnegates the result of thecontainsfunction to makefilterremove the key-value pairs identified indropThesefrom the final output. (Withoutnot, the result is an array of objects containing only the undesired key-value pairs.)
[
{"sequence": "1", "color": "red", "type": "primary", "space": "rgb"}
{"sequence": "2", "color": "green", "type": "primary", "space": "rgb"},
{"sequence": "3", "color": "blue", "type": "primary", "space": "rgb"},
{"sequence": "4", "color": "yellow", "type": "secondary", "space": "rgb"},
{"sequence": "5", "color": "magenta", "type": "secondary", "space": "rgb"},
{"sequence": "6", "color": "cyan", "type": "secondary", "space": "rgb"},
{"sequence": "7", "color": "cyan", "type": "primary", "space": "cmyk"},
{"sequence": "8", "color": "magenta", "type": "primary", "space": "cmyk"},
{"sequence": "9", "color": "yellow", "type": "primary", "space": "cmyk"},
{"sequence": "10", "color": "red", "type": "secondary", "space": "cmyk"},
{"sequence": "11", "color": "green", "type": "secondary", "space": "cmyk"},
{"sequence": "12", "color": "blue", "type": "secondary", "space": "cmyk"}
]
[
{
"sequence": "1",
"color": "red",
"type": "primary",
"space": "rgb"
},
{
"sequence": "2",
"color": "green",
"type": "primary",
"space": "rgb"
},
{
"sequence": "3",
"color": "blue",
"type": "primary",
"space": "rgb"
},
{
"sequence": "10",
"color": "red",
"type": "secondary",
"space": "cmyk"
},
{
"sequence": "11",
"color": "green",
"type": "secondary",
"space": "cmyk"
},
{
"sequence": "12",
"color": "blue",
"type": "secondary",
"space": "cmyk"
}
]



