Contact Us 1-800-596-4880

DataWeave Language

DataWeave 2.1 is compatible with Mule 4.1. Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule will reach its End of Life on November 2, 2022, when Extended Support ends.

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.

DataWeave is the MuleSoft expression language for accessing and transforming data that travels through a Mule app. DataWeave is tightly integrated with the Mule runtime engine, which runs the scripts and expressions in your Mule app.

DataWeave scripts act on data in the Mule event. Most commonly, you use it to access and transform data in the message payload. For example, after a component in your app retrieves data from one system, you can use DataWeave to modify and output selected fields in that data to a new data format, then use another component in your app to pass on that data to another system.

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(

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

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 Design Center, 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.