DataWeave Reference

DataWeave 2.1 is compatible with Mule 4.1. Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule will reach its End of Life on November 2, 2022, when Extended Support ends.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

DataWeave functions are packaged in modules. Functions in the Core (dw::Core) module are imported automatically into your DataWeave scripts. To use other modules, you need to import the module or functions you want to use by adding the import directive to the head of your DataWeave script, for example:

  • import dw::core::Strings

  • import camelize, capitalize from dw::core::Strings

  • import * from dw::core::Strings

The way you import a module impacts the way you need to call its functions from a DataWeave script. If the directive does not list specific functions to import or use * from to import all functions from a function module, you need to specify the module when you call the function from your script. For example, this import directive does not identify any functions to import from the String module, so it calls the pluralize function like this: Strings::pluralize("box").

Transform
%dw 2.0
import dw::core::Strings
output application/json
---
{ 'plural': Strings::pluralize("box") }

The next example identifies a specific function to import from the String module, so it can call the method like this: pluralize("box").

Transform
%dw 2.0
import pluralize from dw::core::Strings
output application/json
---
{ 'plural': pluralize("box") }

The next example imports all functions from the String module, so it can call the method like this: pluralize("box").

Transform
%dw 2.0
import * from dw::core::Strings
output application/json
---
{ 'plural': pluralize("box") }

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub