DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • DataWeave Interview Question: Compare IDs From Two Arrays and Create a New Array
  • DataWeave Interview Question: Find Unique Names From the Input
  • Dataweave Interview Question Using Map and Reduce
  • Merge Multiple PDFs in MuleSoft

Trending

  • Rethinking Java CRUDs With Event Sourcing and CQRS Patterns
  • No More Cheap Claude: 4 First Principles of Token Economics in 2026
  • How to Parse Large XML Files in PHP Without Running Out of Memory
  • Spring AI Advisors: Chat Memory, Token Tracking, and Message Logging
  1. DZone
  2. Coding
  3. Languages
  4. DataWeave Interview Question: Concatenate Elements of an Array

DataWeave Interview Question: Concatenate Elements of an Array

This article will help you practice your DataWeave skills in MuleSoft. We're going to use two different approaches to concatenate an array of letters.

By 
Gaurav Dubey user avatar
Gaurav Dubey
·
Updated Mar. 06, 21 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
8.8K Views

Join the DZone community and get the full member experience.

Join For Free

This article will help you practice your DataWeave skills in MuleSoft. Let's get started.


Input:

JSON
 




x


 
1
["m","u","l","e","s","o","f","t"]



Output:

JSON
 




xxxxxxxxxx
1


 
1
"mulesoft"



Let's talk about the solution now.

We will apply a reduce function to our input and add the value of the item with the value of the accumulator.

Approach 1 Code:

Java
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
output application/json
3
---
4
payload reduce ((item, accumulator) -> accumulator ++ item)



Approach 2 Code:

Java
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
output application/json
3
---
4
payload reduce ($$ ++ $)



Here, $$ stands for accumulator and $ stands for an item.

Output:

JSON
x
 
1
"mulesoft"


If you want reverse output then you can use any of the above approaches with a little modification.

Approach 1 Code:

Java
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
output application/json
3
---
4
payload reduce ((item, accumulator) -> item ++ accumulator)



Approach 2 Code:

Java
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
output application/json
3
---
4
payload reduce ($ ++ $$)



Output:

JSON
 




xxxxxxxxxx
1


 
1
"tfoselum"



Happy Learning!

Data structure Interview (journalism) Element Java (programming language) JSON MuleSoft

Opinions expressed by DZone contributors are their own.

Related

  • DataWeave Interview Question: Compare IDs From Two Arrays and Create a New Array
  • DataWeave Interview Question: Find Unique Names From the Input
  • Dataweave Interview Question Using Map and Reduce
  • Merge Multiple PDFs in MuleSoft

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook