Shows common selector expressions for extracting values from a data source, such as a Mule message.
DataWeave Examples
The following DataWeave examples demonstrate common data extraction and transformation approaches. There are DataWeave code examples of how to transform data, and also examples of Mule applications that implement DataWeave transformations. Before you begin, note that 2.x versions of DataWeave are used by Mule 4 apps. For DataWeave in Mule 3 apps, refer to DataWeave version 1.2 examples. For other DataWeave versions, you can use the version selector in the DataWeave table of contents.
DataWeave Code Examples
These examples show how to use standalone DataWeave to extract and transform data.
Example | Description |
---|---|
Uses a single-value DataWeave selector ( |
|
Shows some common ways to set default values. |
|
Shows how to use and change the settings for reading and writing data formats, such as |
|
Uses selectors to perform a basic format transformation. It does not use any functions. |
|
Uses |
|
Uses |
|
Uses |
|
Uses the |
|
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 |
|
Transforms the payload according to definitions sent in a variable. It defines a function that applies the logic defined in the variable, using |
|
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 |
|
Shows uses of regular expressions in arguments to several DataWeave functions. |
|
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 |
|
Pass XML attributes from the input source payload to the output XML. It uses the dynamic attribute expression |
|
Defines multiple XML namespaces and references these in each tag. |
|
Removes all objects that contain a set of key-value pairs from an array of objects. Uses |
|
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 function that normalizes conflicting date formats into a single, common format. Uses |
|
Performs multiple math operations combining different types related to date and time. |
|
Uses |
|
Uses formatting characters such as |
|
Uses |
|
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 |
|
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 |
DataWeave Code in MuleSoft Applications Examples
These examples show how to use DataWeave to extract and transform data in MuleSoft applications.
Example | Description |
---|---|
Shows how to customize the MIME type of a given format output, including an example of a JSON output with |
|
Uses |
|
Uses |
|
Converts a file stream into Base64 and converts a Base64 string into a file stream. Uses a PDF file as the input and output. |
|
Calls Java methods from a Java class in a Mule project. |
|
Use DataWeave to read and write flat files in a Mule application. |
|
Use a reader property through a Connector operation. |
|
Use a Mule variable as a configuration value. |
|
Use the DataWeave |