SlideShare a Scribd company logo
DataWeave With MuleSoft
Engineering Student MuleSoft
Meetup Group
July 16, 2022
16:30 IST (GMT+05:30)
Safe Harbour Statement
● Both the speaker and the host are organizing this meet-up in individual capacity only. We are
not representing our companies here.
● This presentation is strictly for learning purposes only. Organizer/Presenter do not hold
any responsibility that same solution will work for your business requirements.
● This presentation is not meant for any promotional activities.
2
A recording of this meetup will be uploaded to events page within 24 hours.
Questions can be submitted/asked at any time in the Chat/Questions & Answers Tab.
Make it more Interactive!!!
Give us feedback! Rate this meetup session by filling feedback form at the end of the
day.
We Love Feedbacks!!! Its Bread & Butter for Meetup.
Housekeeping
3
Organizers
4
About the Speaker
Nitish Raj, Lead Software Engineer – EPAM Systems
5
• Started IT journey in 2014 as a Java developer
• Started working on Mule 3.8 in 2016
• Recent MuleSoft Certified Developer Level 2
• Co-Leader of Engineering Student Meetup and
Manchester Meetup group.
• MuleSoft Mentor
Quick recap (Previous meetups)
1. What is MuleSoft and its core capabilities? Quick start with MuleSoft.
2. Start With API Design Using Restful API Modeling Language (RAML)
3. API Implementation using APIKIT router, Anypoint API Manager and API Policies
4. MuleSoft API testing
5. Error Handling With MuleSoft
6. DataWeave Basics
6
What is DataWeave?
● Functional programming language designed for transforming data.
● Expression language used to configure components and connectors
● Can be used to access and evaluate the data in the payload, attributes, and variables of a
Mule event
● Case-sensitive
● Supports auto-complete
● It can be used to take one piece of data, and convert it into a different output format by
adding or removing values.
● It is also available in other contexts, like as a command-line tool.
● Current version: 2.4
7
Sample Use Case
8
• User fills out details and orders
an item
• In the Backend, Mule APIs kick
off to transform the data in
required formats.
• User details are sent to
Salesforce in JSON
• User Address details are the sent
to Database in JAVA format
• User items and billing details are
sent to SAP in XML format.
Architecture of DataWeave Script
● A DataWeave script consists of a header and a body, separated by three dashes
● Header
○ Directives, e.g. Import, Input type, output type, Global vars, functions etc
● Body*
○ The body contains the expression that produces the resulting output, usually a data mapping
or a transformation.
9
%dw 2.0
output application/json
---
payload.message
DataWeave
version (Major)
Header and Body
Separator
(Three dashes)
Body (Generates
the output)
Header contains
directives that apply to
the body expression
Data Types
10
Data Type Definition & Example
String Enclosed by double quotes
E.g. “mulesoft”
Boolean True or False, without any quotes
Number 12345
Date
DateTime
|2020-10-01|
|2020-10-01T23:57:59|
Array* Set of values enclosed in square brackets
E.g.
[1,2,3,4,5 ]
Object* Set of key value pairs enclosed in curly braces {}
E.g.
{“key”: “value”}
{“name”:”nitish”}
Data Operators
● Data operators are symbols that enable you to perform operations on data to produce a
result.
● It is the same as most common programming languages.
11
Operator Description
+ For addition
- For subtraction
* For multiplication
/ For division
Operator Description
< For less than.
> For greater than.
<= For less than or equal to.
>= For greater than or equal to.
== For equal to.
~= Equality operator that tries to
coerce one value to the type
of the other when the types
are different
Operator Description
not Negates the result of the
input.
! Negates the result of the
input.
and Returns true if the result of
all inputs is true, false if not.
or Returns true if the result of
any input is true, false if
not.
Mathematical Operators
Logical Operators
Equality & Relational
Operators
Quiz
● Which one of the below is a valid JSON object
○ [{ "name": "nitish“ }]
○ { "name": "nitish“ }
○ { "name"}
● Which are the examples of a valid Array below
○ [{ "name": "nitish“ }]
○ [1,2,3,4,5]
○ { "name"}
Mule 4 event structure revisit
13
Accessing Mule objects
14
Quiz
● How a query param with a key name can be read using the DataWeave expression?
○ attributes.queryParams.name
○ payload.queryParams.name
Writing expressions for JSON & Java
Input & Output
● The data model can consist of three different types of data: objects, arrays, simple literals
16
Hands On - Walkthrough
● Exploring DataWeave options
○ Transform Message Component
○ Metadata propagation from various connectors (HTTP Listener etc)
● Preview feature
○ Checking Tooling & Restarting
● Checking your DataWeave expression using review feature
● Creating multiple transformations
● Sample Quiz
17
Quiz
● Where does the DataWeave code go?
● Can you save the code externally and reuse it?
DataWeave Selectors
● Traverse the structures of objects and arrays and return matching values.
● Can be used on Payload, variables and everywhere where DataWeave expression is
needed
19
Selector Type Syntax Return Type
Single-value .keyName Any type of value that belongs to a matching key
Multi-value .*keyName Array of values of any matching keys
All repeated, Not in nested structure (Only root key if matched)
Descendants ..keyName Array of values of any matching descendant keys
Not repeated, Only first in each main and nested structure
Index [<index>] Value of any type at selected array index
Range [<index> to <index>] Array with values from selected indexes
Selector
If Else and Else if
20
Operator Description
if else An if operator evaluates a
conditional expression and returns
the value under the if only if the
conditional expression is true.
Otherwise, it returns the expression
under else. Every if expression must
have a matching else expression.
else if An else operator chains expressions
together within an if-else construct
by incorporating else if.
%dw 2.0
output application/json
var data = {"name": "nitish"}
---
if (data.name == "nitish") "Success"
else if (data.name[0] == "n") "Partial
Success"
else "Failure"
if (criteria_expression)
<return_if_true>
else if (criteria_expression)
<return_if_true>
else
<return if no other match>
Map
● Use the map function to apply a transformation to each element in an array.
● The lambda is invoked with two parameters: index and the value. If these parameters are
not named, the index is defined by default as $$ and the value as $.
○ Input can be: JSON or Java Array
○ Returns Array
21
payload map () { }
Payload should
be an array
Function, applied to each element
(Each data in array)
Lambda
MapObject
● Iterates over an object using a mapper that acts on keys, values, or indices of that object.
Accepts Object Returns Object
● Parameters
○ Object: Input to the operator
○ Mapper: Expression that provides the key, value or index used for mapping the specified
object into an output object
22
%dw 2.0
output application/json
var data = { "a":"b","c":"d"}
---
data mapObject {
($$$):
{($$): $}
}
{
"0": {
"a": "b"
},
"1": {
"c": "d"
}
}
Indices
Value
key
Pluck
● Map an object into an array
● Iterates over an object and returns an array of keys, values, or indices from the object.
● Alternative to mapObject but returns Array instead of an array
● Parameters
○ Object: Input to operator
○ Mapper: Expression that provides the key, value or index used for mapping the specified
object into an output object
23
%dw 2.0
output application/json
var data = { "a":"b","c":"d"}
---
data pluck {
($$$):
{($$): $}
}
[
{
"0": {
"a": "b"
}
},
{
"1": {
"c": "d"
}
}
]
Indices
Value
key
Flatten
● Converts a set of sub-arrays into a single flattened array
○ Syntax: flatten(arrayOfArrays)
■ Input: [ [1,2,3], [4,5,[6]], [], [null] ]
■ Output: [ 1, 2, 3, 4, 5, [6], null ]
■ Input should always be an array, that can be array of multiple arrays or any supported data types.
● E.g. Useful in merging output result from Scatter Gather
24
[1,2,3,4,5] [“A”,”B”,”C”,”D”,”E”]
[1,2,3,4,5, “A”,”B”,”C”,”D”,”E”]
Array 1 Array 2
Single Array
Writing expressions for XML output
● XML documents must contain one root element that is the parent of all other elements:
● Speciying attributes for XML output
○ @(attributeName: attributeValue)
■ Attribute Name: Key name of the data
■ Attribute Value: mapped value/ required value
■ Attributes must always be “quoted”
25
<root father=“Mr Muley”>
<child>
<subchild>.....</subchild>
</child>
</root>
Calling a flow from a DataWeave expression
● Lookup function
○ Lookup(“flowToBeCalled”, payload)
■ 3rd argument: Timeout in ms (Optional)
○ Arguments
■ Flow name to be called
■ Payload (data) to be sent
● Limitation
○ Can not call sub-flows
○ Default timeout is 10 seconds, Can be modified
26
Creating multiple transformations
● You can also create multiple transformations with one Transform Message component
27
Quiz
● Does the target of a transformation have to be the payload?
● Is DataWeave expression case sensitive?
● Difference between Map, Map Object and Pluck.
● Does Flatten remove null values?
● Where DWL files are stored in the project structure?
A. src/main/resources
B. src/test/resources
C. sr/main/mule
D. src/test/munit
28
Trivia Quiz
1. Can a DataWeave expression be stored in a variable?
A. True
B. False
2. Which DataWeave operator takes in Object(s) as input and outputs as Array
A. Map
B. Map Object
C. Pluck
D. Concat
29
Trivia Quiz
3. DataWeave lookup() operator can only call the below kind of flow
A. Sub-flow
B. Flow
4. How can an attribute be specified in XML data?
A. @(map: mapObject)
B. @(attributeValue: attributeName)
C. @(attributeName: attributeValue)
30
Introduce yourself to your neighbor
Networking time
Thank you

More Related Content

Similar to Engineering Student MuleSoft Meetup#6 - Basic Understanding of DataWeave With MuleSoft (20)

PPTX
Get started with R lang
senthil0809
 
PDF
Hadoop France meetup Feb2016 : recommendations with spark
Modern Data Stack France
 
PPTX
DataWeave 2.0 Language Fundamentals
Joshua Erney
 
PDF
Software Developer Training
rungwiroon komalittipong
 
PPTX
Structured Languages
Mufaddal Nullwala
 
PDF
learn basic to advance C Programming Notes
bhagadeakshay97
 
PDF
Client sidescripting javascript
Selvin Josy Bai Somu
 
PDF
Introduction to Javascript and Typescript.pdf
rony setyawansyah
 
DOCX
Data structure and algorithm.
Abdul salam
 
PPTX
Aspdot
Nishad Nizarudeen
 
ODP
Oracle SQL Advanced
Dhananjay Goel
 
PDF
Python for web security - beginner
Sanjeev Kumar Jaiswal
 
PPTX
C
Jerin John
 
PDF
Operator_Overloaing_Type_Conversion_OOPC(C++)
Yaksh Jethva
 
PPTX
Input output
nicky_walters
 
PDF
Building Agents with LangGraph & Gemini
HusseinMalikMammadli
 
PPTX
C concepts and programming examples for beginners
SHAAMILIRAJAKUMAR1
 
PDF
ADBMS ASSIGNMENT
Lori Moore
 
PPTX
Operators1.pptx
HARSHSHARMA840
 
DOCX
DataBase Management System Lab File
Uttam Singh Chaudhary
 
Get started with R lang
senthil0809
 
Hadoop France meetup Feb2016 : recommendations with spark
Modern Data Stack France
 
DataWeave 2.0 Language Fundamentals
Joshua Erney
 
Software Developer Training
rungwiroon komalittipong
 
Structured Languages
Mufaddal Nullwala
 
learn basic to advance C Programming Notes
bhagadeakshay97
 
Client sidescripting javascript
Selvin Josy Bai Somu
 
Introduction to Javascript and Typescript.pdf
rony setyawansyah
 
Data structure and algorithm.
Abdul salam
 
Oracle SQL Advanced
Dhananjay Goel
 
Python for web security - beginner
Sanjeev Kumar Jaiswal
 
Operator_Overloaing_Type_Conversion_OOPC(C++)
Yaksh Jethva
 
Input output
nicky_walters
 
Building Agents with LangGraph & Gemini
HusseinMalikMammadli
 
C concepts and programming examples for beginners
SHAAMILIRAJAKUMAR1
 
ADBMS ASSIGNMENT
Lori Moore
 
Operators1.pptx
HARSHSHARMA840
 
DataBase Management System Lab File
Uttam Singh Chaudhary
 

More from Jitendra Bafna (20)

PDF
MuleSoft Surat Meetup#55 - Unleash the power of Anypoint MQ
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#54 - MuleSoft Automation
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#53 - MuleSoft for Clinical Trial Modernization
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#52 - Flex Gateway (Port Based Routing V/S Path Based Ro...
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#51 - API Monitoring - Through a New Lens
Jitendra Bafna
 
PDF
Engineering Student MuleSoft Meetup#7 - Leveraging MuleSoft Service in Salesf...
Jitendra Bafna
 
PDF
MuleSoft Nashik Meetup#7 - Building FHIR applications in MongoDB using MuleSoft
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#50 - Ask the MuleSoft Ambassadors + CloudHub 2.0 Overvi...
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#49 - Robotic Process Automation - Why, Where, When and ...
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#48 - Anypoint API Governance (RAML, OAS and Async API) ...
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#47 - Error Handling With MuleSoft
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#46 - Deep Dive into MUnit With MuleSoft
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#45 - Anypoint Flex Gateway as a Kubernetes Ingress Cont...
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#44 - Anypoint Flex Gateway Custom Policies With Rust
Jitendra Bafna
 
PDF
MuleSoft Nashik Meetup#5 - JSON Logger and Externalize Logs
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#43 - Combine Service Mesh With Anypoint API Management ...
Jitendra Bafna
 
PDF
Engineering Student MuleSoft Meetup#5 - Error Handling With MuleSoft
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#42 - Runtime Fabric Manager on Self Managed Kubernetes ...
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#41 - Universal API Management, Anypoint Flex Gateway an...
Jitendra Bafna
 
PDF
MuleSoft Surat Meetup#40 - Watermarking Concept and Fragments in MuleSoft
Jitendra Bafna
 
MuleSoft Surat Meetup#55 - Unleash the power of Anypoint MQ
Jitendra Bafna
 
MuleSoft Surat Meetup#54 - MuleSoft Automation
Jitendra Bafna
 
MuleSoft Surat Meetup#53 - MuleSoft for Clinical Trial Modernization
Jitendra Bafna
 
MuleSoft Surat Meetup#52 - Flex Gateway (Port Based Routing V/S Path Based Ro...
Jitendra Bafna
 
MuleSoft Surat Meetup#51 - API Monitoring - Through a New Lens
Jitendra Bafna
 
Engineering Student MuleSoft Meetup#7 - Leveraging MuleSoft Service in Salesf...
Jitendra Bafna
 
MuleSoft Nashik Meetup#7 - Building FHIR applications in MongoDB using MuleSoft
Jitendra Bafna
 
MuleSoft Surat Meetup#50 - Ask the MuleSoft Ambassadors + CloudHub 2.0 Overvi...
Jitendra Bafna
 
MuleSoft Surat Meetup#49 - Robotic Process Automation - Why, Where, When and ...
Jitendra Bafna
 
MuleSoft Surat Meetup#48 - Anypoint API Governance (RAML, OAS and Async API) ...
Jitendra Bafna
 
MuleSoft Surat Meetup#47 - Error Handling With MuleSoft
Jitendra Bafna
 
MuleSoft Surat Meetup#46 - Deep Dive into MUnit With MuleSoft
Jitendra Bafna
 
MuleSoft Surat Meetup#45 - Anypoint Flex Gateway as a Kubernetes Ingress Cont...
Jitendra Bafna
 
MuleSoft Surat Meetup#44 - Anypoint Flex Gateway Custom Policies With Rust
Jitendra Bafna
 
MuleSoft Nashik Meetup#5 - JSON Logger and Externalize Logs
Jitendra Bafna
 
MuleSoft Surat Meetup#43 - Combine Service Mesh With Anypoint API Management ...
Jitendra Bafna
 
Engineering Student MuleSoft Meetup#5 - Error Handling With MuleSoft
Jitendra Bafna
 
MuleSoft Surat Meetup#42 - Runtime Fabric Manager on Self Managed Kubernetes ...
Jitendra Bafna
 
MuleSoft Surat Meetup#41 - Universal API Management, Anypoint Flex Gateway an...
Jitendra Bafna
 
MuleSoft Surat Meetup#40 - Watermarking Concept and Fragments in MuleSoft
Jitendra Bafna
 
Ad

Recently uploaded (20)

PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Ad

Engineering Student MuleSoft Meetup#6 - Basic Understanding of DataWeave With MuleSoft

  • 1. DataWeave With MuleSoft Engineering Student MuleSoft Meetup Group July 16, 2022 16:30 IST (GMT+05:30)
  • 2. Safe Harbour Statement ● Both the speaker and the host are organizing this meet-up in individual capacity only. We are not representing our companies here. ● This presentation is strictly for learning purposes only. Organizer/Presenter do not hold any responsibility that same solution will work for your business requirements. ● This presentation is not meant for any promotional activities. 2
  • 3. A recording of this meetup will be uploaded to events page within 24 hours. Questions can be submitted/asked at any time in the Chat/Questions & Answers Tab. Make it more Interactive!!! Give us feedback! Rate this meetup session by filling feedback form at the end of the day. We Love Feedbacks!!! Its Bread & Butter for Meetup. Housekeeping 3
  • 5. About the Speaker Nitish Raj, Lead Software Engineer – EPAM Systems 5 • Started IT journey in 2014 as a Java developer • Started working on Mule 3.8 in 2016 • Recent MuleSoft Certified Developer Level 2 • Co-Leader of Engineering Student Meetup and Manchester Meetup group. • MuleSoft Mentor
  • 6. Quick recap (Previous meetups) 1. What is MuleSoft and its core capabilities? Quick start with MuleSoft. 2. Start With API Design Using Restful API Modeling Language (RAML) 3. API Implementation using APIKIT router, Anypoint API Manager and API Policies 4. MuleSoft API testing 5. Error Handling With MuleSoft 6. DataWeave Basics 6
  • 7. What is DataWeave? ● Functional programming language designed for transforming data. ● Expression language used to configure components and connectors ● Can be used to access and evaluate the data in the payload, attributes, and variables of a Mule event ● Case-sensitive ● Supports auto-complete ● It can be used to take one piece of data, and convert it into a different output format by adding or removing values. ● It is also available in other contexts, like as a command-line tool. ● Current version: 2.4 7
  • 8. Sample Use Case 8 • User fills out details and orders an item • In the Backend, Mule APIs kick off to transform the data in required formats. • User details are sent to Salesforce in JSON • User Address details are the sent to Database in JAVA format • User items and billing details are sent to SAP in XML format.
  • 9. Architecture of DataWeave Script ● A DataWeave script consists of a header and a body, separated by three dashes ● Header ○ Directives, e.g. Import, Input type, output type, Global vars, functions etc ● Body* ○ The body contains the expression that produces the resulting output, usually a data mapping or a transformation. 9 %dw 2.0 output application/json --- payload.message DataWeave version (Major) Header and Body Separator (Three dashes) Body (Generates the output) Header contains directives that apply to the body expression
  • 10. Data Types 10 Data Type Definition & Example String Enclosed by double quotes E.g. “mulesoft” Boolean True or False, without any quotes Number 12345 Date DateTime |2020-10-01| |2020-10-01T23:57:59| Array* Set of values enclosed in square brackets E.g. [1,2,3,4,5 ] Object* Set of key value pairs enclosed in curly braces {} E.g. {“key”: “value”} {“name”:”nitish”}
  • 11. Data Operators ● Data operators are symbols that enable you to perform operations on data to produce a result. ● It is the same as most common programming languages. 11 Operator Description + For addition - For subtraction * For multiplication / For division Operator Description < For less than. > For greater than. <= For less than or equal to. >= For greater than or equal to. == For equal to. ~= Equality operator that tries to coerce one value to the type of the other when the types are different Operator Description not Negates the result of the input. ! Negates the result of the input. and Returns true if the result of all inputs is true, false if not. or Returns true if the result of any input is true, false if not. Mathematical Operators Logical Operators Equality & Relational Operators
  • 12. Quiz ● Which one of the below is a valid JSON object ○ [{ "name": "nitish“ }] ○ { "name": "nitish“ } ○ { "name"} ● Which are the examples of a valid Array below ○ [{ "name": "nitish“ }] ○ [1,2,3,4,5] ○ { "name"}
  • 13. Mule 4 event structure revisit 13
  • 15. Quiz ● How a query param with a key name can be read using the DataWeave expression? ○ attributes.queryParams.name ○ payload.queryParams.name
  • 16. Writing expressions for JSON & Java Input & Output ● The data model can consist of three different types of data: objects, arrays, simple literals 16
  • 17. Hands On - Walkthrough ● Exploring DataWeave options ○ Transform Message Component ○ Metadata propagation from various connectors (HTTP Listener etc) ● Preview feature ○ Checking Tooling & Restarting ● Checking your DataWeave expression using review feature ● Creating multiple transformations ● Sample Quiz 17
  • 18. Quiz ● Where does the DataWeave code go? ● Can you save the code externally and reuse it?
  • 19. DataWeave Selectors ● Traverse the structures of objects and arrays and return matching values. ● Can be used on Payload, variables and everywhere where DataWeave expression is needed 19 Selector Type Syntax Return Type Single-value .keyName Any type of value that belongs to a matching key Multi-value .*keyName Array of values of any matching keys All repeated, Not in nested structure (Only root key if matched) Descendants ..keyName Array of values of any matching descendant keys Not repeated, Only first in each main and nested structure Index [<index>] Value of any type at selected array index Range [<index> to <index>] Array with values from selected indexes Selector
  • 20. If Else and Else if 20 Operator Description if else An if operator evaluates a conditional expression and returns the value under the if only if the conditional expression is true. Otherwise, it returns the expression under else. Every if expression must have a matching else expression. else if An else operator chains expressions together within an if-else construct by incorporating else if. %dw 2.0 output application/json var data = {"name": "nitish"} --- if (data.name == "nitish") "Success" else if (data.name[0] == "n") "Partial Success" else "Failure" if (criteria_expression) <return_if_true> else if (criteria_expression) <return_if_true> else <return if no other match>
  • 21. Map ● Use the map function to apply a transformation to each element in an array. ● The lambda is invoked with two parameters: index and the value. If these parameters are not named, the index is defined by default as $$ and the value as $. ○ Input can be: JSON or Java Array ○ Returns Array 21 payload map () { } Payload should be an array Function, applied to each element (Each data in array) Lambda
  • 22. MapObject ● Iterates over an object using a mapper that acts on keys, values, or indices of that object. Accepts Object Returns Object ● Parameters ○ Object: Input to the operator ○ Mapper: Expression that provides the key, value or index used for mapping the specified object into an output object 22 %dw 2.0 output application/json var data = { "a":"b","c":"d"} --- data mapObject { ($$$): {($$): $} } { "0": { "a": "b" }, "1": { "c": "d" } } Indices Value key
  • 23. Pluck ● Map an object into an array ● Iterates over an object and returns an array of keys, values, or indices from the object. ● Alternative to mapObject but returns Array instead of an array ● Parameters ○ Object: Input to operator ○ Mapper: Expression that provides the key, value or index used for mapping the specified object into an output object 23 %dw 2.0 output application/json var data = { "a":"b","c":"d"} --- data pluck { ($$$): {($$): $} } [ { "0": { "a": "b" } }, { "1": { "c": "d" } } ] Indices Value key
  • 24. Flatten ● Converts a set of sub-arrays into a single flattened array ○ Syntax: flatten(arrayOfArrays) ■ Input: [ [1,2,3], [4,5,[6]], [], [null] ] ■ Output: [ 1, 2, 3, 4, 5, [6], null ] ■ Input should always be an array, that can be array of multiple arrays or any supported data types. ● E.g. Useful in merging output result from Scatter Gather 24 [1,2,3,4,5] [“A”,”B”,”C”,”D”,”E”] [1,2,3,4,5, “A”,”B”,”C”,”D”,”E”] Array 1 Array 2 Single Array
  • 25. Writing expressions for XML output ● XML documents must contain one root element that is the parent of all other elements: ● Speciying attributes for XML output ○ @(attributeName: attributeValue) ■ Attribute Name: Key name of the data ■ Attribute Value: mapped value/ required value ■ Attributes must always be “quoted” 25 <root father=“Mr Muley”> <child> <subchild>.....</subchild> </child> </root>
  • 26. Calling a flow from a DataWeave expression ● Lookup function ○ Lookup(“flowToBeCalled”, payload) ■ 3rd argument: Timeout in ms (Optional) ○ Arguments ■ Flow name to be called ■ Payload (data) to be sent ● Limitation ○ Can not call sub-flows ○ Default timeout is 10 seconds, Can be modified 26
  • 27. Creating multiple transformations ● You can also create multiple transformations with one Transform Message component 27
  • 28. Quiz ● Does the target of a transformation have to be the payload? ● Is DataWeave expression case sensitive? ● Difference between Map, Map Object and Pluck. ● Does Flatten remove null values? ● Where DWL files are stored in the project structure? A. src/main/resources B. src/test/resources C. sr/main/mule D. src/test/munit 28
  • 29. Trivia Quiz 1. Can a DataWeave expression be stored in a variable? A. True B. False 2. Which DataWeave operator takes in Object(s) as input and outputs as Array A. Map B. Map Object C. Pluck D. Concat 29
  • 30. Trivia Quiz 3. DataWeave lookup() operator can only call the below kind of flow A. Sub-flow B. Flow 4. How can an attribute be specified in XML data? A. @(map: mapObject) B. @(attributeValue: attributeName) C. @(attributeName: attributeValue) 30
  • 31. Introduce yourself to your neighbor Networking time