---
schema_version: "1"
id: 3aff499b8478df0af0f452db7f28aa86f8be75a61e03482ee418b0cfd0952432
title: Remove Objects Containing Specified Key-Value Pairs
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.4/dataweave-cookbook-remove-objects.md
canonical_url: https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook-remove-objects
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 78767d81de7e43823e9e4c2ffc64f6e6a4e7c704f24f74dbc3de0cef738aa320
description: MuleSoft Documentation Site
release: "2.4"
latest: false
---
---
product: DataWeave
version: 2.4
keywords: studio, anypoint, transform, transformer, format, aggregate, rename, split, filter convert, xml, json, csv, pojo, java object, metadata, dataweave, data weave, datamapper, dwl, dfl, dw, output structure, input structure, map, mapping
---

# Remove Objects Containing Specified Key-Value Pairs

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

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:

- `filter` iterates over the objects within the input array to return an array with the objects that
  return `true` as the result of an expression. Each object in the input array contains a set of
  key-value pairs. The expression uses the `contains` function and the `not` operator.

- `contains` identifies the key-value pairs specified in the `dropThese` variable. This variable is
  an array of objects containing the key-value pairs to remove.

  `not` negates the result of the `contains` function to make `filter` remove the key-value pairs
  identified in `dropThese` from the final output. (Without `not`, the result is an array of objects
  containing only the _undesired_ key-value pairs.)

DataWeave Script:

```dataweave
%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"}))
```

Input JSON Payload:

```json
[
  { "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" }
]
```

Output JSON:

```json
[
  {
    "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"
  }
]
```

## See Also

- [DataWeave Selectors](https://docs.mulesoft.com/dataweave/2.4/dataweave-selectors)

- [DataWeave Cookbook](https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook)
