---
schema_version: "1"
id: 13a102fea894065e86383fc7ae203443a7716b146727211707b8a1b3174b2895
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.3/dataweave-cookbook-remove-objects.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dataweave-cookbook-remove-objects
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 51d9390e0ffcea8df52088dc446681e5aad62e271ecf4cb67d8b75c673de3b4e
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
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 XML Payload:

```xml
[
    {"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 XML:

```xml
[
  {
    "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.3/dataweave-selectors)

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