DataWeave Evaluation Parentheses: How to Use Them and Why They Matter

We all know that Dataweave is a JSON-like functional programming language used to transform incoming or outgoing data within a Mule application. In this article, we’ll learn about the default Dataweave structure and uses of Evaluation Parentheses.

Whenever we transform any data using Dataweave, it will first convert the input data format to application/dw format and then convert it into the respective output format. let’s see how are the Dataweave looks like (// used for comments)

/*Header Section where we write DW derivatives
Defined the DW version
*/
%dw 2.0
// Defining Output Metadata
output application/json
---
//Writing actual expressions
payload

How to Use Evaluation Parentheses?

Mostly, Dataweave works with Array and Object. While working with objects, Evaluation Parentheses () is used to construct an object using an existing object.


Example

%dw 2.0
output application/json
var object = {
      "name": "Kishan Purohit",
      "domain": "integration-anywhere"
}
---
{
  (object)
}

Output

{
  "name": "Kishan Purohit",
  "domain": "integration-anywhere"
}