Concatenation functions tips and tricks in DataWeave (2024)

In DataWeave 2.0, concatenation can be achieved by using the ++ (plus plus) function. However, there are two additional syntax options to concatenate objects and one to concatenate strings in DataWeave. Concatenation is when you link two strings, objects, data types etc together in a chain or series.

In many cases, when dealing with large datasets, these different concatenation methods may be helpful to you to make data transformations easier. In this tutorial, we are going to highlight a few functions. You can test these functions out yourself in the DataWeave Playground, in Visual Studio Code, or in Anypoint Studio using a Transform Message component. The screenshots from this tutorial were created using the DataWeave Playground.

Using ++ to concatenate objects and strings

You can achieve string concatenation from two or more strings, using the ++ function. Here’s an example:

Concatenation functions tips and tricks in DataWeave (1)

Open in Playground

You can also concatenate two or more objects and get one flattened object in return, using the ++ function, like this:

Concatenation functions tips and tricks in DataWeave (2)

Open in Playground

Using $() to concatenate strings

We already reviewed how to concatenate two or more strings when using the ++ function, but sometimes you need to keep adding spaces in between strings, and you end up with something like this:

Concatenation functions tips and tricks in DataWeave (3)

Open in Playground

If you surround your variables in $(), you 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 and I find it cleaner to concatenate several strings.

Concatenation functions tips and tricks in DataWeave (4)

Open in Playground

Notice that I used the ++ function for the last concatenation because str5 and str6 didn’t need a space in-between.

What $() is doing is executing the expression that’s inside and returns a string that can be concatenated with the rest. You can’t create expressions that will not be able to be converted into a string. For example, if you try to concatenate an array with this syntax, you will get an error stating that it was expecting a string.

Concatenation functions tips and tricks in DataWeave (5)

Open in Playground

However, if you work with numbers, DataWeave can transform the result into a string without a problem. You may get a warning saying something like “Auto-Coercing type from: Number to: String.” You can avoid this by explicitly transforming the expression into a string. However, this is not necessary to correctly run the application.

Concatenation functions tips and tricks in DataWeave (6)

Open in Playground

Using the object destructor to concatenate objects

Another way to concatenate objects involves using the object destructor. This is done by surrounding an object in parentheses (), and then surrounding those in curly brackets {}. The object destructor is capable of destroying an array containing objects or destroying an object into key/value pairs. The outer curly brackets {} will then construct a new object containing these key/value pairs.

An example of this syntax, using the previous example, would go like this:

Concatenation functions tips and tricks in DataWeave (7)

Open in Playground

You’ll notice that you have to surround each object in parentheses for it to work. As mentioned, the object destructor can also destroy an array containing objects. Below is an example of how to do this:

Concatenation functions tips and tricks in DataWeave (8)

Open in Playground

When using this function, you don’t need to surround each object by parentheses because you’re surrounding the array with them. Thus, the array contains the objects to be concatenated. I hope that these examples were useful to you and you feel confident in concatenating functions in DataWeave using more than just the ++ function.

Next steps

Hope you enjoyed this tutorial on DataWeave concatenation. If you found this article helpful, please rate the tutorial below. This article only covered the very basics of what’s possible with DataWeave, make sure to checkout the more tutorials on DataWeave by viewing our full catalog of developer tutorials.

Concatenation functions tips and tricks in DataWeave (2024)
Top Articles
Slash and Burn Agriculture: Effects & Example
Africa: Human Geography | National Geographic Society
Patreon, reimagined — a better future for creators and fans
Restored Republic January 20 2023
Midflorida Overnight Payoff Address
Black Gelato Strain Allbud
St Als Elm Clinic
Teenbeautyfitness
CKS is only available in the UK | NICE
라이키 유출
Atrium Shift Select
Crime Scene Photos West Memphis Three
Natureza e Qualidade de Produtos - Gestão da Qualidade
South Ms Farm Trader
Ktbs Payroll Login
Lima Crime Stoppers
Purple Crip Strain Leafly
R/Afkarena
Aspen.sprout Forum
Seattle Rpz
Minecraft Jar Google Drive
Lonesome Valley Barber
Bing Chilling Words Romanized
Hampton University Ministers Conference Registration
Inkwell, pen rests and nib boxes made of pewter, glass and porcelain.
800-695-2780
Culver's.comsummerofsmiles
Jackass Golf Cart Gif
Robert A McDougal: XPP Tutorial
Duke Energy Anderson Operations Center
Human Unitec International Inc (HMNU) Stock Price History Chart & Technical Analysis Graph - TipRanks.com
Appleton Post Crescent Today's Obituaries
Skroch Funeral Home
Lake Dunson Robertson Funeral Home Lagrange Georgia Obituary
How Much Is Mink V3
Usf Football Wiki
Craigs List Palm Springs
Mcalister's Deli Warrington Reviews
18006548818
Gotrax Scooter Error Code E2
Jaefeetz
Senior Houses For Sale Near Me
Copd Active Learning Template
Stitch And Angel Tattoo Black And White
The Machine 2023 Showtimes Near Roxy Lebanon
Here’s What Goes on at a Gentlemen’s Club – Crafternoon Cabaret Club
Sam's Club Fountain Valley Gas Prices
Bluebird Valuation Appraiser Login
Renfield Showtimes Near Regal The Loop & Rpx
Gelato 47 Allbud
Craigslist Centre Alabama
Dr Seuss Star Bellied Sneetches Pdf
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 6065

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.