Overview
DataWeave 2.0 is the transformation and expression language of Mule 4. A script has a header, with the version, an output directive such as output application/json and optional var, fun, type and import declarations, then three dashes and a body expression. The same language powers Transform Message components and the #[ ] expressions in every other processor, so fluency pays off across the exam.
The exam guide calls this section Transforming Data and lists five objectives: convert between output types and data types; predict the result of core DataWeave functions; write transformations that coerce, format, order and filter data and predict outcomes; call Mule flows from a DataWeave script; and define, use and reuse DataWeave modules, functions and variables. Questions show short scripts with sample input and ask for the output, or show a requirement and ask which script produces it. Exact syntax matters, including parentheses, the $ shorthand and format strings.
How it's tested
Most questions show a payload and a DataWeave script, then offer four possible outputs that differ in a key name, a type, an order or a missing element. Others ask which script meets a stated transformation. Read the header first: the output type and any declared functions change how the body behaves.
-
Predict the output
Given input and a script using map, filter, groupBy or orderBy, you choose the exact resulting structure.
-
Pick the syntax
A requirement to format a date, round a number or coerce a string leads you to the correct as expression and format.
-
Reuse and call out
You choose how to import a module function or call a flow from a script with lookup.
The input is an array of products with name and price, and the script is payload filter ($.price > 20) orderBy -$.price map {item: upper($.name)}. Filter keeps items above 20, orderBy with a negated numeric key sorts them from highest to lowest price, and map builds new objects with upper-case names. An option that sorts ascending or keeps the original key names is wrong.
Objectives 5
Official objectives from the Salesforce outline, in outline order.
8.1 Convert between output types and data types using DataWeave.Output directives, readers and writers for JSON, XML, CSV and Java.
- What it means
- The output directive, such as output application/json, application/xml, application/csv or application/java, decides how DataWeave writes the result. Input is read according to its MIME type, so the same script logic can turn XML into JSON or CSV into Java objects.
- What to understand
- Know the format rules: XML output needs a single root element, so an array must be wrapped in an object first; XML attributes are read with .@ and written with @(name: value); CSV output needs an array of flat objects; application/java produces Java maps and lists for connectors that expect objects. Writer properties such as indent=false or header=false adjust the output. The data type of a value, such as String or Number, is separate from the output format, which matters when coercing values within a JSON output.
- How it shows up
- You choose the script or output directive that turns given input into a required format.
- Common confusion
- Writing an array directly as XML fails because XML requires one root element.
8.2 Predict the result of core DataWeave functions.map, filter, reduce, groupBy, pluck, mapObject and friends.
- What it means
- Core functions in the dw::Core module are available without import. Common ones include map and filter on arrays, mapObject and filterObject on objects, pluck to turn an object into an array, reduce to accumulate, groupBy, orderBy, distinctBy, flatten, sizeOf, contains, splitBy, joinBy, upper, lower and now.
- What to understand
- Each lambda receives positional parameters: map gives $ for the item and $$ for the index, while mapObject gives $ for the value, $$ for the key and $$$ for the index. groupBy returns an object keyed by the grouping value. reduce takes an item and an accumulator, and starts with the first element unless you set the accumulator's initial value. Learn the selectors too: .field, .*field for multi-value, ..field for descendants, [0] for index and [0 to 2] for ranges.
- How it shows up
- A short script with one or two functions is shown, and you choose the exact output.
- Common confusion
- map works on arrays; applying it to an object needs mapObject or pluck.
8.3 Apply correct syntax to write DataWeave transformations to coerce, format, order, and filter data, and predict outcomes.The as operator, format strings, orderBy and filter.
- What it means
- Coercion uses as with a type, for example "42" as Number or payload.date as Date {format: "dd/MM/yyyy"}. Formatting uses the same operator in the other direction, such as amount as String {format: "#,##0.00"} or now() as String {format: "yyyy-MM-dd"}. orderBy sorts, and filter keeps elements that match a condition.
- What to understand
- Date and time patterns follow Java conventions, so MM is month and mm is minutes. Number patterns use # and 0. orderBy sorts ascending; for descending order, negate a numeric key or reverse the result with [-1 to 0]. The default operator supplies a fallback when a value is null. Coercing an invalid string to Number raises an error, so validate or use default where data may be missing.
- How it shows up
- A requirement to output a date or currency in a set format leads you to choose the as expression.
- Common confusion
- mm means minutes and MM means month in format strings, a frequent wrong-answer trigger.
8.4 Call Mule flows from a DataWeave script.The lookup function.
- What it means
- lookup("flowName", value) calls a flow in the same application from within a DataWeave script, passing value as the payload, and returns the flow's resulting payload. This lets a transformation reuse logic that lives in a flow, such as a lookup against a database.
- What to understand
- lookup can call flows but not subflows. The called flow receives a new event built from the argument and does not see the caller's variables or attributes. Because each call runs a flow, calling lookup inside a map over a large array triggers one flow execution per element, which can be slow. Errors raised in the called flow surface as errors in the DataWeave expression.
- How it shows up
- You choose the expression that calls a flow from a Transform Message, or predict what it returns.
- Common confusion
- lookup cannot target a subflow; the target must be a flow, which can be a private flow without a source.
8.5 Define, use, and reuse DataWeave modules, functions, and variables, and predict outcomes.var, fun, type and modules in src/main/resources.
- What it means
- In the header, var declares a constant, fun declares a function and type declares a custom type, such as type Currency = String {format: "#,##0.00"}. A module is a .dwl file, usually under src/main/resources/modules, containing reusable declarations without an output directive or body separator.
- What to understand
- Import a module with import modules::Utils and call Utils::fnName(), or with import * from modules::Utils or import fnName from modules::Utils to call fnName() directly. A module can also be packaged in a library and shared through Exchange. Local variables can be scoped inside a do block. Functions can be overloaded by parameter type, and lambdas can be assigned to variables. Custom types make coercion and formatting rules reusable across scripts.
- How it shows up
- You pick the correct import and call syntax for a function defined in a module file.
- Common confusion
- A module file has no output directive and no --- separator; adding them makes it a script, not a module.
High-yield concepts
The terms, rules and formulas this domain turns into questions most often.
-
Script structure
Header with %dw 2.0, output, var, fun, type and import, then --- and the body.
- Remember
- The output directive controls the written format.
- Tested as
- Every script question.
- Trap
- Ignoring the header when predicting output.
-
map vs mapObject
map transforms each array element; mapObject transforms each key and value of an object.
- Remember
- $ and $$ mean different things in each.
- Tested as
- Function prediction questions.
- Trap
- Using map on an object.
-
filter and orderBy
filter keeps matching elements; orderBy sorts ascending by a criterion.
- Remember
- Negate a number key or reverse with [-1 to 0] for descending.
- Tested as
- Ordering and filtering objective.
- Trap
- Expecting descending order by default.
-
groupBy
Groups array elements into an object keyed by a value.
- Remember
- Result is an object, not an array.
- Tested as
- Output structure questions.
- Trap
- Expecting an array of arrays.
-
reduce
Accumulates array elements into a single value.
- Remember
- Accumulator defaults to the first element without an initial value.
- Tested as
- Totals and aggregations.
- Trap
- Assuming it starts at zero.
-
as coercion and format
Converts types and applies format patterns to dates and numbers.
- Remember
- MM is month, mm is minutes.
- Tested as
- Formatting questions.
- Trap
- Mixing up pattern letters.
-
default operator
Returns a fallback when the left side is null.
- Remember
- Prevents null errors in formatting and concatenation.
- Tested as
- Missing-value scenarios.
- Trap
- Expecting it to catch type errors.
-
lookup()
Calls a flow from DataWeave with a value as its payload.
- Remember
- Flows only, not subflows.
- Tested as
- Call-flow objective.
- Trap
- Choosing a subflow name.
-
Modules
Reusable .dwl files imported with import modules::Name.
- Remember
- No output directive or body separator.
- Tested as
- Reuse objective.
- Trap
- Calling a module function without its namespace when imported by module name.
-
Custom type
type declaration that names a type with optional format properties.
- Remember
- Used with as for consistent coercion.
- Tested as
- Reuse of formatting rules.
- Trap
- Confusing it with a variable declaration.
Side by side
Concepts candidates mix up, compared on the point that decides the answer.
Array and object functions
| Concept | Meaning | Key difference | Common trap |
|---|---|---|---|
| map | Array to array, one output per element | $ is item, $$ is index | Applying it to an object |
| mapObject | Object to object, per key and value | $ is value, $$ is key | Expecting an array result |
| pluck | Object to array, per key and value | Turns entries into list items | Confusing it with mapObject |
| groupBy | Array to object keyed by criterion | Collects matching elements under each key | Expecting an array output |
Reusing logic
| Concept | Meaning | Key difference | Common trap |
|---|---|---|---|
| var and fun in header | Declarations local to one script | Visible only in that script | Expecting reuse in other components |
| Module (.dwl file) | Shared declarations imported into many scripts | Imported with import modules::Name | Adding an output directive to the module |
| lookup() to a flow | Runs Mule flow logic from a script | Executes connectors and processors | Targeting a subflow |
Exam traps
Each trap is an answer that looks right. Learn the clue that should change your mind.
-
Descending by default
- What candidates pick
- Assuming orderBy sorts from high to low.
- Why it looks right
- Many ranking requirements are descending.
- Why it's wrong
- orderBy sorts ascending; negate the key or reverse the array for descending.
Clue to watch for The requirement says highest first.
-
groupBy returns an array
- What candidates pick
- Choosing an array of grouped arrays.
- Why it looks right
- Grouping sounds like partitioning a list.
- Why it's wrong
- groupBy returns an object whose keys are the grouping values.
Clue to watch for Output options differ only in brackets versus braces.
-
Month vs minute
- What candidates pick
- A format of yyyy-mm-dd for a date.
- Why it looks right
- Lowercase looks consistent.
- Why it's wrong
- mm is minutes; dates need yyyy-MM-dd.
Clue to watch for Format strings in the options differ only by case.
-
Subflow lookup
- What candidates pick
- lookup("enrichSubflow", payload).
- Why it looks right
- Subflows are the usual reusable unit.
- Why it's wrong
- lookup supports flows only, so a subflow name fails.
Clue to watch for The target is described as a subflow.
-
Module as script
- What candidates pick
- A module file with output application/json and ---.
- Why it looks right
- It looks like every other DataWeave file.
- Why it's wrong
- Modules contain only declarations; the importing script defines output and body.
Clue to watch for The question is about a reusable .dwl file.
-
reduce starts at zero
- What candidates pick
- Expecting reduce to start counting from 0.
- Why it looks right
- Sums usually start at zero.
- Why it's wrong
- Without an explicit initial accumulator, reduce starts with the first element.
Clue to watch for The accumulator has no initial value in the script.
Answer framework
Work through DataWeave prediction questions in this order to avoid small but costly mistakes.
- Read the header: note the output type, any declared variables, functions, types and imports before reading the body, because they change how the body behaves.
- Identify the input type and structure, then resolve every selector to the values it returns.
- Apply functions from left to right as written, noting that map, filter and orderBy each return a new array and that groupBy returns an object.
- Check coercion and format strings carefully, especially MM versus mm, HH versus hh and number patterns with # and 0.
- Compare the result with each option for key names, brackets versus braces, order and data types such as quoted numbers.
Practice question
Want more like this? The Mule-Dev-201 practice test has questions for every domain.
Checklist
0 of 11
Tick each one you can do without notes. Your ticks stay in this browser.
Study strategy
DataWeave rewards daily practice more than long sessions. Use the DataWeave Playground or a Transform Message preview in Anypoint Studio and write at least ten small scripts a day for two weeks. Start with selectors and map, filter and mapObject, then add groupBy, orderBy, reduce and pluck. For each script, predict the output on paper before you run it.
In the second week, focus on coercion and formatting with dates and currency values, and on format conversions between JSON, XML and CSV. Build one module with two functions and a custom type, import it into a Transform Message in different ways, and call a flow with lookup.
Keep a list of every prediction you got wrong and the reason. Most errors repeat, such as ascending order, month versus minutes, or object versus array output, and reviewing that list in the last few days before the exam is worth more than new material.
FAQ
How much of Mule-Dev-201 is Transforming Data?
Transforming Data is 10% of the exam, about six of the 60 scored questions. DataWeave also appears inside questions in most other sections.
Why is the section called Transforming Data and not Transforming Data with DataWeave?
The current Salesforce exam guide uses the heading Transforming Data. All five objectives are about DataWeave 2.0, so the content is the same.
Which DataWeave version is tested?
DataWeave 2.0, the version used in Mule 4. Scripts start with %dw 2.0. DataWeave 1.0 syntax from Mule 3 is not part of the current exam.
Can lookup call a subflow?
No. lookup calls a flow by name, passing a value as the payload and returning the flow's resulting payload. Subflows are not supported.
Where do DataWeave modules live in a Mule project?
Typically in src/main/resources, often in a modules folder, and they are imported with import modules::FileName. Modules can also be shared as libraries through Exchange.
What is the best way to practise DataWeave?
Use the online DataWeave Playground or Transform Message preview in Studio, predict each output before running it, and track the mistakes you repeat.
Do I need to know every function in dw::Core?
Focus on the common ones: map, filter, mapObject, pluck, groupBy, orderBy, reduce, distinctBy, flatten, sizeOf, joinBy, splitBy, upper, lower and now, plus the default operator.
Other CRM & Business Applications certifications
Where the same subject shows up in other exams. Cards marked "Same subject" open the matching domain.
- HubSpot Inbound Marketing Certification Study guide
- Salesforce Certified Platform Developer I Study guide
- Google Ads Search Certification Study guide
- ServiceNow Certified System Administrator Study guide
- Salesforce Certified Platform Administrator Study guide
- ServiceNow Certified Application Developer Study guide
Test your Domain 8 knowledge
You have studied DataWeave output types, core functions, coercion, lookup and modules. Test how quickly you can predict script output in Mule-Dev-201 practice questions.
Keep going
- Training Training Built on your Weak areas
- Practice test Questions by domain, with explanations
- Mock exam Full length, timed like the real exam
- Readiness test Find your weakest domain in minutes
- Cheat sheet Key terms and formulas on one page
- Ask the Mule-Dev-201 AI tutor Get any concept explained your way