Introduction to Mule 4: DataWeave 2.0

Standard Support for Mule 4.2 ended on May 2, 2021, and this version of Mule will reach its End of Life on May 2, 2023, 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 2 is largely unchanged from DataWeave 1. However, MuleSoft made many improvements to make it easier to learn and added new capabilities.

Operators Are Functions

In DataWeave 2, all operators are now functions. While this can involve more parentheses, it is less ambiguous and more friendly to learn through auto-completion features. The previous syntax continues to work for functions with two parameters, providing a shorter syntax for power users.

DataWeave 1

sizeOf payload filter $.age > 30

DataWeave 2 - Function Syntax

sizeOf(filter(payload, (value) → value.age > 30)))

DataWeave 2 - Shortcut Syntax

sizeOf(payload filter $.age > 30)

Traits Are Functions

DataWeave 1

payload is :empty

DataWeave 2

isEmpty(payload)

Type Names

DataWeave 2 uses a type name syntax, which removes the : from the name.

DataWeave 1

payload.foo as :string

DataWeave 2

payload.foo as String

XML Format

The default for the reader property nullValueOn is empty for DataWeave 2.0.

For DataWeave 1.0 (which is compatible with Mule 3.x), the value is none, for example:

DataWeave Script
%dw 1.0
%output application/xml nullValueOn="none"
---
payload
Input
<book>
  <name></name>
</book>
Output
<book/>

New Capabilities

There are also many new capabilities, including:

  • Typing for reusable functions

  • Multi-line comments

  • Ability to call out to Java code

  • Multipart, URL-encoded, and text readers and writers

  • Modules and imports

  • and more

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub