- MuleSoft - Discussion
- MuleSoft - Useful Resources
- MuleSoft - Quick Guide
- MuleSoft - Testing with MUnit
- MuleSoft - Mule exception Handling
- MuleSoft - Mule Error Handling
- Web Services Using Anypoint Studio
- Flow Control and Transformers
- MuleSoft - Endpoints
- Core Components & Their Configuration
- Message Processor & Script Components
- MuleSoft - DataWeave Language
- Creating First Mule Application
- MuleSoft - Discovering Anypoint Studio
- MuleSoft - Anypoint Studio
- MuleSoft - Mule in Our Machine
- MuleSoft - The Mule Project
- MuleSoft - Introduction to Mule ESB
- MuleSoft - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MuleSoft - DataWeave Language
DataWeave is basically a MuleSoft expression language. It is mainly used for accessing and transforming the data received through a Mule apppcation. Mule runtime is responsible for running the script and expressions in our Mule apppcation, DataWeave is strongly integrated with Mule runtime.
Features of DataWeave Language
Following are some important features of DataWeave language −
Data can be transformed from one format to another very easily. For example, we can transform apppcation/json to apppcation/xml. The input payload is as follows −
{ "title": "MuleSoft", "author": " tutorialspoint.com ", "year": 2019 }
Following is the code in DataWeave for transform −
%dw 2.0 output apppcation/xml --- { order: { type : Tutorial , title : payload.title, author : upper(payload.author), year : payload.year } }
Next, the output payload is as follows −
<?xml version = 1.0 encoding = UTF-8 ?> <order> <type>Tutorial</type> <title>MuleSoft</title> <author>tutorialspoint.com</author> <year>2019</year> </order>
The transform component can be used for creating scripts that performs both simple as well as complex data transformations.
We can access and use core DataWeave functions on parts of the Mule event that we need as most of the Mule message processors support DataWeave expressions.
Prerequisites
We need to satisfy the following prerequisites before using DataWeave scripts on our computer −
Anypoint Studio 7 is required to use Dataweave scripts.
After instalpng Anypoint Studio, we need to set up a project with a Transform Message component in order to use DataWeave scripts.
Steps for Using DataWeave Script with Example
In order to use DataWeave scrip, we need to follow the steps below −
Step 1
First, we need to set up a new project, as we did in the previous chapter, by using File → New → Mule Project.
Step 2
Next, we need to provide the name of the project. For this example, we are giving the name, Mule_test_script.
Step 3
Now, we need to drag the Transform Message component from Mule Palette tab into canvas. It is shown as below −
Step 4
Next, in the Transform Message component tab, cpck on Preview to open Preview pane. We can expand the source code area by cpcking the empty rectangle next to Preview.
Step 5
Now, we can start scripting with DataWeave language.
Example
Following is the simple example of concatenating two strings into one −
The above DataWeave script is having a key-value pair ({ myString: ("hello" ++ "World") }) which will concatenate two strings into one.
Advertisements