Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

To Create a DataWeave Module

You can encapsulate custom functions, variables, namespaces and types into reusable modules, which you can then import into any DataWeave code. This saves you from having to define these in the DataWeave header every time.

Modules are stored in regular .dwl files in your project folder, they use the same syntax as any other transformation file.

For example, below is a module you can import elsewhere. This module defines a function, a variable and a namespace. The body of the transformation is also packaged as a function called main. If the module is imported into another DataWeave file, all of these can be referenced as if they were declared in the header.

Example

         
      
1
2
3
4
5
%dw 2.0
fun myFunc(name: String) = name ++ " Test"
var name = "MyData"
ns mynamespace http://acme.com/bar
output application/json

In this topic: