DataWeave Examples
DataWeave 2.2 is compatible and bundled with Mule 4.2. This version of Mule reached its End of Life on May 2, 2023, when Extended Support ended. 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. |
The examples demonstrate common data extraction and transformation approaches.
Before you begin, note that DataWeave version 2 (%dw 2.0
) is for Mule 4 apps. For a
Mule 3 app, refer to DataWeave 1.0
(%dw 1.0
) examples,
within the Mule 3.9 documentation set. For other Mule versions, you can use
the Mule Runtime version selector in the table of contents.
Example | Description |
---|---|
Shows common selector expressions for extracting values from a data source, such as a Mule message. |
|
Shows some common ways to set default values. |
|
Uses selectors to perform a basic format transformation. It does not use any functions. |
|
Uses |
|
Uses |
|
Uses |
|
Uses the multi-value selector to pick out the keys in an object that are named "book", these are returned as an array. It then uses |
|
Uses |
|
Renames some keys in a JSON object while retaining the names of all other keys in the output. Uses |
|
Uses |
|
Uses |
|
Uses |
|
Uses |
|
Uses |
|
Masks sensitive data by changing values of some keys to asterisks ( |
|
Shows how to exclude unwanted elements from the output. Uses the |
|
Defines a series of constant strings and numbers in the header, these are used to filter input and to concatenate into URLs. Uses |
|
Defines a function that obtains totals and subtotals through the |
|
Uses |
|
Uses |
|
Uses |
|
Uses the |
|
Defines a function that recursively checks an element and all of its children for a specific XML attribute and removes it with |
|
Defines multiple XML namespaces and references these in each tag. |
|
References data on the payload, a message attribute and a variable. It then processes these through |
|
Reference data that arrives in multiple separate payloads from one single Mule event. Filters the output based on a unique identifier. Uses |
|
Defines a |
|
Defines a function that normalizes conflicting date formats into a single, common format. Uses |
|
Performs multiple math operations combining different types related to date and time. |
|
Defines a function that reduces a list of elements into one field. It then calls this function only when a certain field has values. Uses |
|
Transforms the payload according to definitions sent in a variable. It defines a function that applies the logic defined in the variable, using |
|
Defines a function that expects to receive two inputs: a function to apply and an element to apply it on. The function is also recursively applied to the element’s children. It uses |