---
schema_version: "1"
id: c4e2bd434e8b40154b8f0c7be71417674f6ca55aaadf770cfb6f3534a90ea96b
title: mergeWith
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-objects-functions-mergewith.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-objects-functions-mergewith
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 3f6fe5bfe23758f07bc352c9c09fd27c95aa69943a3287e19c2043de5c95e3de
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# mergeWith

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

## mergeWith<T <: Object, V <: Object>(source: T, target: V): ?

Appends any key-value pairs from a source object to a target object.

If source and target objects have the same key, the function appends that source object to the
target and removes that target object from the output.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>source</code></p></td><td><p>The object to append to the <code>target</code>.</p></td></tr><tr><td><p><code>target</code></p></td><td><p>The object to which the <code>source</code> object is appended.</p></td></tr></tbody></table>

### Example

This example appends the source objects to the target. Notice that `"a" : true,` is removed from the
output, and `"a" : false` is appended to the target.

#### Source

```DataWeave
%dw 2.0
import mergeWith from dw::core::Objects
output application/json
---
{ "mergeWith" : { "a" : true, "b" : 1} mergeWith { "a" : false, "c" : "Test"} }
```

#### Output

```JSON
"mergeWith": {
    "b": 1,
    "a": false,
    "c": "Test"
}
```

## mergeWith<T <: Object>(a: Null, b: T): T

Helper function that enables `mergeWith` to work with a `null` value.

## mergeWith<T <: Object>(a: T, b: Null): T

Helper function that enables `mergeWith` to work with a `null` value.
