SlideShare a Scribd company logo
July 21, 2023 12:30pm (EST)
Oklahoma City MuleSoft Meetup Group
The Secrets of Dataweave
2
● Introductions
● Our Sponsors
● The Secrets of Dataweave
● Trivia Game
● SPECIAL Dataweave Challenge!!!
● Exciting announcements
Welcome!
3
●Meet the Organizers:
○ Victor Felisbino
○ Ryan Hoegg
○ Diane Kesler
●Meet the Sponsors:
○ AVIO Consulting – Mike Slack
○ Hoegg Software - Ryan Hoegg
Introductions
Where are you joining this Meetup From?
The Secrets of Dataweave
Juan Cruz Basso
Senior Software Engineer at
Avio Consulting
• Software Engineer
• 13+ years in the world of integrations
• MuleSoft Certified Developer L1/L2
• MuleSoft Certified Integration Architect
• MuleSoft Certified Platform Architect
• MuleSoft Mentor
/jcbasso
Agenda
● Dataweave basic structure
● Functional programing principal concepts
● Functional concepts applied in Dataweave
● Modularization
● Demo
● Dataweave tips
● Q & A
Structure of a Dataweave Script
● It has a header and a body separated by (---)
○ Header: Contains language directives, such as input/output format, the version of DataWeave to
execute, properties of readers/writers, and definitions of variables or functions.
○ Body: Contains the DataWeave expression that generates the output of the script.
7
Functional programming concepts
● Pure functions
● First class functions
● High order functions
● Lamda functions
● Function composition
Pure Functions
%dw 2.0
output application/java
fun incOne(param,param2) = param + 1
—
incOne(payload,1)
9
Payload: 1
Payload: 2
incOne(1,1) Payload: 2
incOne(2,1) Payload: 3
%dw 2.0
output application/java
fun incOne(param,param2) = param + 1
—
payload incOne 1
Execution Nro 1
Execution Nro 2
Infix Notation Prefix Notation
First Class Functions
%dw 2.0
output application/java
fun incOne(param) = param + 1
fun processArray(array, func) = array map
func($)
—
processArray(payload,incOne)
10
%dw 2.0
output application/java
fun incOne(param) = param + 1
fun processArray(array, func) = array map
func($)
—
payload processArray incOne
%dw 2.0
output application/java
var incOne = (param) -> param
+ 1
—
incOne(payload)
%dw 2.0
output application/java
fun incOne(param) = param +
1
—
payload incOne
Declare a function as a variable
Infix Notation
Prefix Notation
High Order Functions
11
%dw 2.0
output application/java
var inputData = [1]
fun processArray(array, func) = array map func($)
fun incrementFunction(increment1) = (increment2) -> (increment1 + increment2)
fun incOne(param) = incrementFunction(1)(param)
fun incTwo(param) = incrementFunction(2)(param)
---
processArray(inputData,incOne) ++ processArray(inputData,incTwo) ++ processArray(inputData,incrementFunction(5))
Function Composition
12
%dw 2.0
output application/java
var arrayInput = ["string1", "string2", "1string3"]
---
((arrayInput filter ($ contains "1"))
map (item,index) -> upper(item) ++ index)
%dw 2.0
output application/java
var arrayInput = ["string1", "string2", "1string3"]
var filterItems = (item,index) -> item contains "1"
fun upperPlusIndex(item,index) = upper(item) ++ index
---
map( filter (arrayInput,filterItems) , upperPlusIndex)
Prefix Notation
Infix Notation
Core Functions
● They are functions created for data transformation, and it is not necessary to explicitly import them
in the scripts.
● Think of them as tools for solving different problems, there are more libraries around, but they
need to be explicitly imported.
● Some commonly used core functions are:
○ map
○ filter
○ reduce
○ isEmpty
○ flatten
○ flatMap
○ pluck
○ sizeOf
○ read
○ write
○ …
Modularization
● Promotes code reusability
● Inside of them we can define functions, variables, types, or Dataweave scripts.
● Functions are imported by using the module name followed by ::
○ We can import all the elements of the module using:
■ import * from modules::utilsModule
○ We can import specific elements of the module using:
■ import numberToSAP from modules::utilsModule
Modularization in a Mulesoft API
● Promotes code reusability within the implementation of a single MuleSoft API.
● They are located within the "resources" folder of the MuleSoft application.
15
Modularization as an Exchange Library
● Promotes code reusability within the implementation of multiple MuleSoft APIs.
● They are published on Exchange.
● They are included as Maven dependencies in the project's pom.xml file.
● MuleSoft Runtime
● CLI scripts
● Playground
● VS Code
● Dataweave in Apex (Beta)
Execution contexts
17
Demo
Tips when developing with Dataweave
● Use do to create partial context of execution to define “local” variables
● Use log() to trace intermediate results of the transformations for troubleshooting
● The object destructor is a powerful tool to concatenate objects, or transform them into
key/value pairs. (aka surround with () and then with {} )
● Be aware of the in the usage of () in the correct way, the parenthesis defines the scope of the
results and how the operations like ! or functions will impact.
Links
● https://dataweave.mulesoft.com
● https://docs.mulesoft.com/dataweave/2.4/dataweave-language-guide
● Core functions doc: https://docs.mulesoft.com/dataweave/2.4/dw-core
● Cheat Sheet : https://www.prostdev.com/post/dataweave-2-0-core-functions-cheatsheet
● Memory management : https://docs.mulesoft.com/dataweave/2.4/dataweave-memory-
management#buffersize
● Dataweave in Apex (Beta): https://developer.salesforce.com/docs/atlas.en-
us.apexcode.meta/apexcode/DataWeaveInApex.htm
Trivia Game!
22
Trivia Game
Three winners of today’s trivia
receives:
A $30 Gift Card!
● Remember:
○ The first correct answer wins!
○ You can only receive 1 Gift Card
● Gift Cards are sponsored by
23
1. How many parameters should have a function to be used with an
infix notation?
A. 1
B. 3
C. 2
D. any
Trivia Question 1
24
2. How many functions can I pass as parameters in a function in
Datawave?
A. 1
B. any
C. 2
D. 0
Trivia Question 2
25
3. When a function is a first-class function in a programming
language?
A. when it flights only in first class
B. when it's the first function written in the code
C. when it can be treated as an object ( having the same
"privileges" )
D. when it's the first function called of a program
Trivia Question 3
DATA WEAVE CHALLENGE!
27
Dataweave Challenge!
input : [{
"message": "Hello world 1!",
"weight": 1,
"color": "red"
}
,
{
"message": "Hello world 2!",
"weight": 2,
"color": "blue"
}
,
{
"message": "Hello world 3!",
"weight": 3,
"color": "green"
}
]
output: {
"byWeight": [
{
"message": "Hello world 3!",
"weight": 3,
"color": "green"
}
],
"byColor": [
{
"message": "Hello world 2!",
"weight": 2,
"color": "blue"
}
]
}
Here is your Input Desired Output
script: %dw 2.0
output application/json
---
{
byWeight: payload filterByWeight 3,
byColor: payload filterByColor 'blue'
}
?
Send us your
Functions!
What’s Next?
● Share:
○ Tweet using the hashtag #MuleSoftMeetups
○ Invite your network to join: https://meetups.mulesoft.com/oklahoma-city/
○ Want to be a Speaker? Let us know at:
● Feedback:
○ Fill out the survey feedback – Win MuleSoft Swag! Drawing from completed surveys
○ Suggest topics for upcoming events: What are YOUR requests?
○ Contact MuleSoft at meetups@mulesoft.com for ways to improve the program
29
What’s next?
30
We are here
to help YOU!
20230721_OKC_Meetup_MuleSoft.pptx
Thank you & See you next time!

More Related Content

PDF
Flyte kubecon 2019 SanDiego
PDF
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...
PPTX
Mule soft meetup_virtual_ charlotte_2020_final1
KEY
Titanium appcelerator best practices
PDF
Introduction to Elixir
PPTX
DataWeave 2.0 Language Fundamentals
PDF
Introduction to interactive data visualisation using R Shiny
PDF
Writing DSL with Applicative Functors
Flyte kubecon 2019 SanDiego
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...
Mule soft meetup_virtual_ charlotte_2020_final1
Titanium appcelerator best practices
Introduction to Elixir
DataWeave 2.0 Language Fundamentals
Introduction to interactive data visualisation using R Shiny
Writing DSL with Applicative Functors

Similar to 20230721_OKC_Meetup_MuleSoft.pptx (20)

PPT
An Overview Of Python With Functional Programming
PPTX
PyData NYC 2019
PDF
Hack Like It's 2013 (The Workshop)
PPTX
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
PPT
Oops lecture 1
PPTX
brief introduction to core java programming.pptx
PPTX
C++ Overview PPT
PDF
Computer Project For Class XII Topic - The Snake Game
PPTX
CHAPTER 01 FUNCTION in python class 12th.pptx
PPTX
Novidades do c# 7 e 8
PPTX
Introduction to F#
PDF
C++ Programming
PDF
Exploring Clojurescript
PPTX
Dartprogramming
PDF
PPTX
Things about Functional JavaScript
PDF
mobl
PDF
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
An Overview Of Python With Functional Programming
PyData NYC 2019
Hack Like It's 2013 (The Workshop)
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
Oops lecture 1
brief introduction to core java programming.pptx
C++ Overview PPT
Computer Project For Class XII Topic - The Snake Game
CHAPTER 01 FUNCTION in python class 12th.pptx
Novidades do c# 7 e 8
Introduction to F#
C++ Programming
Exploring Clojurescript
Dartprogramming
Things about Functional JavaScript
mobl
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
Ad

Recently uploaded (20)

PPTX
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
PDF
Event Presentation Google Cloud Next Extended 2025
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Dell Pro 14 Plus: Be better prepared for what’s coming
PDF
KodekX | Application Modernization Development
PPTX
How to Build Crypto Derivative Exchanges from Scratch.pptx
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
How AI Agents Improve Data Accuracy and Consistency in Due Diligence.pdf
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
ai-archetype-understanding-the-personality-of-agentic-ai.pdf
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Top Generative AI Tools for Patent Drafting in 2025.pdf
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PPTX
Web Security: Login Bypass, SQLi, CSRF & XSS.pptx
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
Event Presentation Google Cloud Next Extended 2025
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Dell Pro 14 Plus: Be better prepared for what’s coming
KodekX | Application Modernization Development
How to Build Crypto Derivative Exchanges from Scratch.pptx
Reimagining Insurance: Connected Data for Confident Decisions.pdf
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
CIFDAQ's Market Insight: SEC Turns Pro Crypto
How AI Agents Improve Data Accuracy and Consistency in Due Diligence.pdf
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
madgavkar20181017ppt McKinsey Presentation.pdf
ai-archetype-understanding-the-personality-of-agentic-ai.pdf
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
Transforming Manufacturing operations through Intelligent Integrations
Top Generative AI Tools for Patent Drafting in 2025.pdf
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Web Security: Login Bypass, SQLi, CSRF & XSS.pptx
Ad

20230721_OKC_Meetup_MuleSoft.pptx

  • 1. July 21, 2023 12:30pm (EST) Oklahoma City MuleSoft Meetup Group The Secrets of Dataweave
  • 2. 2 ● Introductions ● Our Sponsors ● The Secrets of Dataweave ● Trivia Game ● SPECIAL Dataweave Challenge!!! ● Exciting announcements Welcome!
  • 3. 3 ●Meet the Organizers: ○ Victor Felisbino ○ Ryan Hoegg ○ Diane Kesler ●Meet the Sponsors: ○ AVIO Consulting – Mike Slack ○ Hoegg Software - Ryan Hoegg Introductions Where are you joining this Meetup From?
  • 4. The Secrets of Dataweave
  • 5. Juan Cruz Basso Senior Software Engineer at Avio Consulting • Software Engineer • 13+ years in the world of integrations • MuleSoft Certified Developer L1/L2 • MuleSoft Certified Integration Architect • MuleSoft Certified Platform Architect • MuleSoft Mentor /jcbasso
  • 6. Agenda ● Dataweave basic structure ● Functional programing principal concepts ● Functional concepts applied in Dataweave ● Modularization ● Demo ● Dataweave tips ● Q & A
  • 7. Structure of a Dataweave Script ● It has a header and a body separated by (---) ○ Header: Contains language directives, such as input/output format, the version of DataWeave to execute, properties of readers/writers, and definitions of variables or functions. ○ Body: Contains the DataWeave expression that generates the output of the script. 7
  • 8. Functional programming concepts ● Pure functions ● First class functions ● High order functions ● Lamda functions ● Function composition
  • 9. Pure Functions %dw 2.0 output application/java fun incOne(param,param2) = param + 1 — incOne(payload,1) 9 Payload: 1 Payload: 2 incOne(1,1) Payload: 2 incOne(2,1) Payload: 3 %dw 2.0 output application/java fun incOne(param,param2) = param + 1 — payload incOne 1 Execution Nro 1 Execution Nro 2 Infix Notation Prefix Notation
  • 10. First Class Functions %dw 2.0 output application/java fun incOne(param) = param + 1 fun processArray(array, func) = array map func($) — processArray(payload,incOne) 10 %dw 2.0 output application/java fun incOne(param) = param + 1 fun processArray(array, func) = array map func($) — payload processArray incOne %dw 2.0 output application/java var incOne = (param) -> param + 1 — incOne(payload) %dw 2.0 output application/java fun incOne(param) = param + 1 — payload incOne Declare a function as a variable Infix Notation Prefix Notation
  • 11. High Order Functions 11 %dw 2.0 output application/java var inputData = [1] fun processArray(array, func) = array map func($) fun incrementFunction(increment1) = (increment2) -> (increment1 + increment2) fun incOne(param) = incrementFunction(1)(param) fun incTwo(param) = incrementFunction(2)(param) --- processArray(inputData,incOne) ++ processArray(inputData,incTwo) ++ processArray(inputData,incrementFunction(5))
  • 12. Function Composition 12 %dw 2.0 output application/java var arrayInput = ["string1", "string2", "1string3"] --- ((arrayInput filter ($ contains "1")) map (item,index) -> upper(item) ++ index) %dw 2.0 output application/java var arrayInput = ["string1", "string2", "1string3"] var filterItems = (item,index) -> item contains "1" fun upperPlusIndex(item,index) = upper(item) ++ index --- map( filter (arrayInput,filterItems) , upperPlusIndex) Prefix Notation Infix Notation
  • 13. Core Functions ● They are functions created for data transformation, and it is not necessary to explicitly import them in the scripts. ● Think of them as tools for solving different problems, there are more libraries around, but they need to be explicitly imported. ● Some commonly used core functions are: ○ map ○ filter ○ reduce ○ isEmpty ○ flatten ○ flatMap ○ pluck ○ sizeOf ○ read ○ write ○ …
  • 14. Modularization ● Promotes code reusability ● Inside of them we can define functions, variables, types, or Dataweave scripts. ● Functions are imported by using the module name followed by :: ○ We can import all the elements of the module using: ■ import * from modules::utilsModule ○ We can import specific elements of the module using: ■ import numberToSAP from modules::utilsModule
  • 15. Modularization in a Mulesoft API ● Promotes code reusability within the implementation of a single MuleSoft API. ● They are located within the "resources" folder of the MuleSoft application. 15
  • 16. Modularization as an Exchange Library ● Promotes code reusability within the implementation of multiple MuleSoft APIs. ● They are published on Exchange. ● They are included as Maven dependencies in the project's pom.xml file.
  • 17. ● MuleSoft Runtime ● CLI scripts ● Playground ● VS Code ● Dataweave in Apex (Beta) Execution contexts 17
  • 18. Demo
  • 19. Tips when developing with Dataweave ● Use do to create partial context of execution to define “local” variables ● Use log() to trace intermediate results of the transformations for troubleshooting ● The object destructor is a powerful tool to concatenate objects, or transform them into key/value pairs. (aka surround with () and then with {} ) ● Be aware of the in the usage of () in the correct way, the parenthesis defines the scope of the results and how the operations like ! or functions will impact.
  • 20. Links ● https://dataweave.mulesoft.com ● https://docs.mulesoft.com/dataweave/2.4/dataweave-language-guide ● Core functions doc: https://docs.mulesoft.com/dataweave/2.4/dw-core ● Cheat Sheet : https://www.prostdev.com/post/dataweave-2-0-core-functions-cheatsheet ● Memory management : https://docs.mulesoft.com/dataweave/2.4/dataweave-memory- management#buffersize ● Dataweave in Apex (Beta): https://developer.salesforce.com/docs/atlas.en- us.apexcode.meta/apexcode/DataWeaveInApex.htm
  • 22. 22 Trivia Game Three winners of today’s trivia receives: A $30 Gift Card! ● Remember: ○ The first correct answer wins! ○ You can only receive 1 Gift Card ● Gift Cards are sponsored by
  • 23. 23 1. How many parameters should have a function to be used with an infix notation? A. 1 B. 3 C. 2 D. any Trivia Question 1
  • 24. 24 2. How many functions can I pass as parameters in a function in Datawave? A. 1 B. any C. 2 D. 0 Trivia Question 2
  • 25. 25 3. When a function is a first-class function in a programming language? A. when it flights only in first class B. when it's the first function written in the code C. when it can be treated as an object ( having the same "privileges" ) D. when it's the first function called of a program Trivia Question 3
  • 27. 27 Dataweave Challenge! input : [{ "message": "Hello world 1!", "weight": 1, "color": "red" } , { "message": "Hello world 2!", "weight": 2, "color": "blue" } , { "message": "Hello world 3!", "weight": 3, "color": "green" } ] output: { "byWeight": [ { "message": "Hello world 3!", "weight": 3, "color": "green" } ], "byColor": [ { "message": "Hello world 2!", "weight": 2, "color": "blue" } ] } Here is your Input Desired Output script: %dw 2.0 output application/json --- { byWeight: payload filterByWeight 3, byColor: payload filterByColor 'blue' } ? Send us your Functions!
  • 29. ● Share: ○ Tweet using the hashtag #MuleSoftMeetups ○ Invite your network to join: https://meetups.mulesoft.com/oklahoma-city/ ○ Want to be a Speaker? Let us know at: ● Feedback: ○ Fill out the survey feedback – Win MuleSoft Swag! Drawing from completed surveys ○ Suggest topics for upcoming events: What are YOUR requests? ○ Contact MuleSoft at [email protected] for ways to improve the program 29 What’s next?
  • 30. 30 We are here to help YOU!
  • 32. Thank you & See you next time!