800-596-4880 ](tel:1-800-596-4880)

Online  [ Contact Us ](https://www.mulesoft.com/contact)

  * Login 

[ Anypoint Platform
](https://anypoint.mulesoft.com/login/#/signin?apintent=generic) [ Composer
](https://composer.mulesoft.com/login/sign-in) [ Training
](https://training.mulesoft.com/login) [ Help Center
](https://help.mulesoft.com/s/login/)

[ Free trial ](https://anypoint.mulesoft.com/login/#/signup?apintent=generic)

[ Link to MuleSoft Twitter profile  ](https://twitter.com/MuleSoft) [ Link to
MuleSoft Linkedin profile  ](https://www.linkedin.com/company/mulesoft) [ Link
to MuleSoft Facebook page  ](https://www.facebook.com/MuleSoft) [ Link to
MuleSoft Instagram profile  ](https://www.instagram.com/mulesoft/) [ Link to
MuleSoft Videos platform  ](https://videos.mulesoft.com/) [ Link to MuleSoft
Twitch profile  ](https://www.twitch.tv/mulesoft_community)

© Copyright 2024  Salesforce, Inc. [ All rights reserved
](https://www.salesforce.com/company/legal/intellectual/) .

![](../../_/img/icons/arrow-down.svg)

Skip to main content

[ View on GitHub ](https://github.com/mulesoft/docs-
dataweave/blob/v2.6/modules/ROOT/pages/dw-objects-functions-mergewith.adoc)

#  On this page:

Menu

  1. [ Homepage  ](../../general/)
  2. [ DataWeave (2.6) ](./)
  3. [ DataWeave Reference ](dw-functions)
  4. [ dw::core::Objects ](dw-objects)
  5. mergeWith 

![](../../_/img/icons/arrow-down.svg) ![](../../_/img/icons/search.svg)

  1. [ Homepage  ](../../general/)
  2. [ DataWeave (2.6) ](./)
  3. [ DataWeave Reference ](dw-functions)
  4. [ dw::core::Objects ](dw-objects)
  5. mergeWith 

#  mergeWith

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

Name  |  Description   
---|---  
` source ` |  The object to append to the ` target ` .   
` target ` |  The object to which the ` source ` object is appended.   
  
###  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

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

####  Output

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

Back to top

Did this article solve your issue?

Let us know so we can improve!

Yes

![](../../_/img/icons/like.svg)

No

![](../../_/img/icons/dislike.svg)

Please check at least 1 checkbox.

Would you like to share any additional feedback? (Optional)

![](../../_/img/icons/success.svg) Your feedback has been successfully
submitted. Thank you!  [ View on GitHub ](https://github.com/mulesoft/docs-
dataweave/blob/v2.6/modules/ROOT/pages/dw-objects-functions-mergewith.adoc)

  * Products 
    * [ Anypoint Platform ](https://www.mulesoft.com/platform/enterprise-integration)
    * [ MuleSoft Composer ](https://www.mulesoft.com/platform/composer)
    * [ MuleSoft RPA ](https://www.mulesoft.com/platform/rpa)
    * [ Start a free trial ](https://anypoint.mulesoft.com/login/signup?apintent=generic)
    * [ Download Studio ](https://www.mulesoft.com/lp/dl/studio)
  * Solutions 
    * [ API management ](https://www.mulesoft.com/platform/api-management)
    * [ Integration ](https://www.mulesoft.com/integration-solutions/dataweave-integration)
    * [ Automation ](https://www.mulesoft.com/integration-solutions/api/business-automation)
    * [ See all solutions ](https://www.m