Contact Us 1-800-596-4880

DataWeave Language

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 simple example below demonstrates a few important features of the DataWeave language:

  • Data transformation from one format to another. The example transforms application/json input to application/xml output.

  • Data selectors that access fields within an input data structure. The script selects keys in a JSON object from the message payload input (for example, with payload.title) and then outputs their values.

  • Use of a core DataWeave function on the value of an input field upper(payload.author).

Before you begin, note that DataWeave version 2 is for Mule 4 apps. For a Mule 3 app, refer to the DataWeave 1.0 documentation set in the Mule 3.9 documentation. For other Mule versions, you can use the version selector for the Mule Runtime table of contents.

Input Payload
{
  "title": "Java 8 in Action",
  "author": "Mario Fusco",
  "year": 2014
}
Transform
%dw 2.0
output application/xml
---
{
  order: {
    'type': 'Book',
    'title': payload.title,
    'author': upper(payload.author),
    'year': payload.year
  }
}
Output Payload
<?xml version='1.0' encoding='UTF-8'?>
<order>
  <type>Book</type>
  <title>Java 8 in Action</title>
  <author>MARIO FUSCO</author>
  <year>2014</year>
</order>

Far more complex data manipulation and transformations are possible.

DataWeave supports several file input and output formats in addition to XML and JSON. It provides a number of functions for manipulating data and includes selectors for accessing fields in the data structure. It can handle a number of data types in addition to arrays, key-value pairs, Java objects, strings, and numbers. It also supports type coercion, and the creation and use of your own functions, data types, and variables in your scripts.

You write DataWeave expressions and scripts within message processors (components, connectors, or modules) when creating apps in Anypoint Studio or as handwritten XML configuration files.

  • The Transformer component is for creating scripts that perform data transformations, whether simple format conversions or complex data extraction and transformation processes.

  • Many Mule message processors support DataWeave expressions, allowing you to access and use core DataWeave functions on parts of the Mule event that you need.

    See the inline DataWeave script examples for Set Payload in DataWeave Scripts. For other examples, see the message attribute in Logger Component examples, Set Payload (<ee:set-payload>) and Set Variable components in the For Each Scope examples, and <file:content> in the File Connector documentation.