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

  • Mule 3 DataWeave(1.x) Script To Resolve Wildcard Dynamically
  • Import a Function/Module in Dataweave
  • Five Nonprofit & Charity APIs That Make Due Diligence Way Less Painful for Developers
  • Java String: A Complete Guide With Examples

Trending

  • AWS Managed Database Observability: Monitoring DynamoDB, ElastiCache, and Redshift Beyond CloudWatch
  • The Update Problem REST Doesn't Solve
  • Why SAP S/4HANA Landscape Design Impacts Cloud TCO More Than Compute Costs
  • 11 Agentic Testing Tools to Know in 2026
  1. DZone
  2. Data Engineering
  3. Data
  4. 10 Quick Dataweave Functions

10 Quick Dataweave Functions

This quick reference collects many Dataweave functions for MuleSoft in one place, like reversing strings and flattening and trimming a payload.

By 
Satheesh Kumar user avatar
Satheesh Kumar
·
Jun. 06, 17 · Opinion
Likes (9)
Comment
Save
Tweet
Share
84.6K Views

Join the DZone community and get the full member experience.

Join For Free

Since Dataweave is new in MuleSoft, it's hard to identify how to do some basic functions like substring reversing a string. This guide will provide all the functions in one place, which saves developers time. Below is the JSON I am using as a sample payload.

{
"firstName":"satheesh",
"lastName":"Kumar",
"age":"26",
"Amount":10.5
}

1. Substring

Most of us need to use substring somewhere in Dataweave, and it's very simple.We have to use the range operator the range can be mentioned as in array.

 firstName: payload.firstName[0..3]  will give you "firstName": "sath."

2. Reverse a String

Reversing a string is made very easy in Dataweave, so when you have a palindrome or not program next time, you don't need to use Java. You can use it directly in Dataweave.

 firstName: payload.firstName[-1..0]  will give you "firstName": "hseehtas."

3. Replace

To replace a string with another, the replace function is used.

 firstName: (payload.firstName replace "s" with "new")  will give you "firstName": "newatheenewh."

4. Identify the Size of the String

To identify the size of any value, the size of operator is used. It's not only for strings- it's for measuring arrays or lists, too.

 sizeOfFirstName: sizeOf payload.firstName  will give you "sizeOfFirstName": 8.

5. Concat

Concatenation is made very easy in Dataweave; it can be done by just using   + operator .

 Name: payload.firstName ++ " " ++ payload.lastName  will give you  "Name": "satheesh Kumar."

6. Trim

Trimming unwanted spaces is always required in integrations.

When the first name is "       satheesh," use  Name: trim payload.firstName  and it will give you "Name": "satheesh."

7. Other String Operations

I don't need to explain this as the example says everything.

Input Function Sample Result
satheesh capitalize

Name: capitalize payload.firstName

Name:Satheesh
satheesh_mule_developer camelize

Name: camelize payload.firstName

satheeshMuleDeveloper
monday tuesday dasherize

Name: dasherize payload.firstName

monday-tuesday
child

pluralize

Name: pluralize payload.firstName

children
cars singularize

Name: singularize payload.firstName

car
SAtheesh lower

Name: singularize payload.firstName

satheesh
SaTheesh upper

Name: singularize payload.firstName

SATHEESH


8. Flatten

When you have a multiple array list from multiple sources as shown below, Flatten will be very handy.

[{
"firstName":"cars",
"lastName":"Kumar",
"age":"26",
"Amount":10.5
}],
[{
"firstName":"cars",
"lastName":"Kumar",
"age":"26",
"Amount":10.5
}]

 flatten.payload  will give you

[{
"firstName":"cars",
"lastName":"Kumar",
"age":"26",
"Amount":10.5
},
 {
"firstName":"cars",
"lastName":"Kumar",
"age":"26",
"Amount":10.5
}]

9. Floor and Ceil

The Floor function will round down the decimal value into an integer and Ceil will round up the decimal value into an intenger.

"age":26.5

 age: floor payload.age  will give you 26.

 age: ceil payload.age  will give you 27.

10. Now

The Now function will give you the current date and time.

 currentTime: now  will give you "currentTime": "2016-10-20T17:15:06.196Z."

Strings Data Types IT Operator (extension) Data structure JSON Space (architecture) Java (programming language) dev

Opinions expressed by DZone contributors are their own.

Related

  • Mule 3 DataWeave(1.x) Script To Resolve Wildcard Dynamically
  • Import a Function/Module in Dataweave
  • Five Nonprofit & Charity APIs That Make Due Diligence Way Less Painful for Developers
  • Java String: A Complete Guide With Examples

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