Concatenation Functions in Dataweave

Author: Putul Mandal

In this blog, we will be performing concatenation in DataWeave 2.0 for several data types. Here, I will be using the DataweaveEditor to demonstrate the varying functions, but you can create this in Anypoint Platform with a transform message components as well.

  • ++ function to concatenate Objects and Strings:
  1. To Concatenate two or more Objects:

Here’s the example where we can achieve the concatenation of two or more objects:

  1. To Concatenate two or more Strings:

And here’s the example where we can achieve the concatenation of two or more strings:

  • $() to Concatenate Strings:

Here we can see that when we are using ++ function for concatenation & we have to add spaces in between. In the example below we can see that the highlighted part is where we are not adding spaces in between:

But when we use $() for concatenation, we can keep writing in a single line as if it was just one string, instead of using the ++ function for each variable. This removes the extra space.

Here we can notice that I have used the ++ function for concatenation where we didn’t need a space in between. Here the $() is executing the expression that inside and returns a string that can be concatenated with the rest.
Here we can’t create expressions that will not be able to converted into a string for eg. if we use an array with this syntax we will get an error.

  • Object Destructor to Concatenate Objects:

Object destructor is also a way to concatenate objects.This is done by surrounding an object  in parentheses ( ), and then surrounding those in curly brackets { }.Here is the example shown below:

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.