Transforming Data10% of the exam
DataWeave modules, functions and variables
How to build a custom .dwl module under src/main/resources and import it (module prefix, import *, named elements, aliases), how fun declarations take typed and optional parameters (including right-to-left assignment when optional parameters come first), and how global vars, do-scoped local vars and lambda vars behave.
Define, use, and reuse DataWeave modules, functions, and variables, and predict outcomes.
~7 min read · 5 practice questions ·
What the exam expects
- Create a reusable custom module in
src/main/resourcesand know what it may and may not contain. - Import a module or its elements (
import modules::X,import * from, named elements,asaliases) and call them with or without theX::prefix. - Define functions with
fun, type constraints and optional parameters, and predict how arguments bind. - Predict the scope and lifetime of global
vars,do-scoped local variables and lambdas assigned to variables. - Key terms: custom module (a
.dwlfile ofvar,fun,typeandnsdeclarations); mapping file (a.dwlfile holding a complete script, called throughmain); alias (a local name assigned withasat import); optional parameter (a parameter with a default value);doscope (a header-and-body block that declares local variables); lambda (an anonymous function such as(s) -> upper(s)).
Key facts
Module contents
- Detail
- Only
var,fun,type,ns; nooutput,---or body
Module location
- Detail
- Under
src/main/resources, e.g.src/main/resources/modules/MyModule.dwl
import modules::M- Detail
- Calls need the prefix:
M::myFunc
import * or named import- Detail
- No prefix needed
Alias
- Detail
asrenames a module or element to avoid name clashes
Mapping file
- Detail
- Has a body; call it with
Module::main(...)
Argument binding
- Detail
- Left to right; right to left when optional parameters come first or all are optional
Immutability
- Detail
- DataWeave variables cannot be reassigned
do scope- Detail
- Local variables visible only inside the scope
Lifetime
- Detail
- DataWeave variables do not persist beyond the script and are not Mule event variables
- What does the documented
MyMapping::main(payload: { "user" : "bar" })return? - Why does
allParametersOptional('A')setparam3rather thanparam1? - Why does a
doscope need the---separator? - What does
fundo relative tovarfor a lambda?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the MuleSoft Developer pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 40 lessons of the MuleSoft Developer guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Practice exams purchase adds inline bank questions and topic practice (5 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams