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

# 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.
