Over a million developers have joined DZone.

Dataweave Method for Dataweave Expression in Mule

DZone 's Guide to

Dataweave Method for Dataweave Expression in Mule

Mule comes with a lot of neat out of the box features. In this article, we explore one such feature that allows you to transform data/payloads.

· Integration Zone ·
Free Resource

As we know the power of the Dataweave language in Mule to transform a message format from one state to required state.

Below is one example to help you utilize Dataweave methods to transform data/payloads using out of the box components.

Dataweave methods provide a feature to explicitly create a user-defined data format.

In this post, we will demonstrate the use of Dataweave expressions outside of the Dataweave Transform component by using the  dw() function.

Use Case Example

Let us assume we have a payload (JSON format) and want to input our own format/structure. The JSON payload will enter into our Mule application as an input and will get transformed into a modified JSON payload/JSON  payload as output.

Image title

The output from the above code should look like what I've got below:

Image title

Now the same transformation of state could be used outside of Dataweave components: 

Image title

Let us create a Mule flow that will contain an HTTP listener to accept the input JSON payload followed by an "Object to String" and "Object to JSON" with a set payload that will execute our  dw() function as shown below.

Sample flow:

Image title

  Testing flow:    

Image titleOutput:

Image title

This is a very powerful feature provided by Mule.

Happy learning! 

dataweave ,mulesoft ,integration

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}