SlideShare a Scribd company logo
Data weave
Using the DataWeave Transformer
 In Anypoint Studio, you can place a Transform
Message element in a flow to create transformations
using the DataWeave language.
 The editor helps you do this by offering intelligent
autocomplete suggestions, an output preview that is
updated in real time as you make changes.
 This generates a .dwl transformation file (or several of
them) that stores your code and is packaged with your
Mule application.
 When adding a Transform Message element to a Mule
Flow, it takes the elements from the incoming Mule
Message as its inputs. It then performs the necessary
actions to produce a Mule message as output for the
next element in the flow
 The DataWeave Text Editor GUI
 The Transform Message element allows you to freely
write DataWeave code.
 If you click on an instance of the Transform Message
element in your flow, its properties editor will be
displayed. This editor is divided into three sections:
 Input
 Transform
 Output
Input Section
In the main tab, a tree view shows the known metadata
contents of the incoming Mule Message, allowing you to
explore it and know what data is available for using as an
input, and how to reference each part of it.
If the Mule flow doesn’t expose Metadata about the
elements you need from the incoming message, you can
manually specify it. To do so, select the element of the
input you desire to define, note that the pencil icon at
the top right is no longer grayed out. Click this icon to
open a new tab in your input section where you can
define a sample with the structure of this data.
When the input is of JSON or XML types, the sample input contains plain XML or JSON
code. When the input is of type POJO or DataWeave, the sample input is written
in DataWeave for more simplicity. In these cases the sample DataWeave code is merely a
way to display the sample data, not a transformation in itself.
Setting Reader Parameters
 Some input formats, like CSV, allow you to define a
reader with specific properties that make
DataWeave parse inputs differently. Select the
input element you wish to configure on the tree
view of the input section, then click the gear icon.
Transform Section
 you write the actual DataWeave code that carries out
the transform. Notice that changing the type of your
output directive changes the output section of the
editor. Although DataWeave as a language supports
adding input directives and naming these by any name
you like, in Studio the elements of the input message
are implicitly considered input directives and so they
don’t need to be defined in the header.
If Studio has any metadata about the components that
are upstream or downstream from your Transform
Message element at the time when you add the
component to your flow, a scaffolding for
your DataWeave code is written out automatically, with
as much depth as Studio can intelligently deduce. In
some cases, this code may be enough to carry out the
transformation you need, and no additional coding is
needed. Sometimes, all you need to do is fill in the blank
spaces in the scaffolding with references to the input
fields, other times you may want to carry out more
complex operations that involve aggregation, filtering,
calculations, defining custom functions, etc and there
you must write this out in DataWeave code.
Re-scaffolding Once you’ve added the Transform Message element
to your flow, any further changes you make to the
surrounding message processors and their metadata
won’t affect your `.dw`l file. You may still click the
Scaffolding button on the top left of the DataWeave
properties editor any time you want and have a new
scaffolding built, note that this will erase anything
you’ve written in the DataWeave body. Doing this
won’t affect any directives you defined in your header
(except for the output directive). Use this button if
you’ve made any changes to elements that come after
the Transform Message element on the flow that
expose metadata and don’t mind loosing what you’ve
already written into the transform’s body.
Referencing Existing Transforms
Instead of defining a new .dwl file, you can reference an
existing one by clicking theData Source button,
selecting On File as the source and referencing the
correct file.
Handling Multiple Outputs
A single Transform Message element can give shape to
several different components of the output Mule
message. Each of these output components must be
defined in a separate .dwl file, written out in a separate
tab of the Transform section. For example in one tab you
may be defining the payload contents, in another those
of an outbound property, and these will both be parts of
the same output Mule message
To add a new output, click the Plus sign at the
bottom right of the section:new+output.png[image]
A new tab will then appear, there you can specify
where in the output Mule message to place the
output of this DataWeave transform. In case you’re
creating a new variable or property, you must also
set a name for it.
In the XML editor you can do the same by adding
multiple child elements inside thedw:transform-
message component.
<dw:transform-message>
<dw:set-payload resource="classpath:path/transform.dwl"/> <dw:set-
variable variableName="myVariable"
resource="classpath:path/transform.dwl"/> <dw:set-session-variable
variableName="mySessionVariable"
resource="classpath:path/transform.dwl"/> </dw:transform-message>
Output Section
 This section has two tabs, one of them shows you a neat
expandable tree view of the output data structure, the
other shows you a preview of what the actual output looks
like, built from any sample data you provide in the input
section. As you make changes in the transport section,
notice how the data structure changes. The output of the
transformer is made into the selected component of the
output mule message. If your transformer has multiple
outputs, the Preview tab will display the one
corresponding to the currently selected transform.
Using DataWeave Language
Elsewhere
 All components in Mule that support Mule Expression
Language also support expressions written in DataWeave
Language. To invoke an expression written in DataWeave
language, simply invoke the dw() function, the expression
will return whatever the transform outputs.
 DataWeave expressions defined within this function work
just as those defined within a Transform Message element,
the only difference is that the output is returned into the
expression’s result, wherever it may be.
 For example, you can define a custom object and
populate it with elements from the payload:
 That same expression could be added inside a Logger,
 within a MEL expression, to print out its result:
dw(myobject:{id:payload.accountid, user:payload.user})
#[`dw(myobject:{id:payload.accountid, user:payload.user})`]

More Related Content

PPTX
Dataweave by nagarjuna
PPTX
Data weave
PPTX
Dataweave
PDF
Data weave
PPTX
Dataweave Basic
PPTX
Data weave documentation
PPTX
Data weave component
PDF
Murach: How to use Entity Framework EF Core
Dataweave by nagarjuna
Data weave
Dataweave
Data weave
Dataweave Basic
Data weave documentation
Data weave component
Murach: How to use Entity Framework EF Core

What's hot (14)

PDF
Responsive Design and Bootstrap
DOCX
OBIEE publisher with Report creation - Tutorial
PDF
Oracle Form material
DOC
Generic steps in informatica
PDF
Oracle Certification 1Z0-1041 Questions and Answers
PPT
Rational Publishing Engine with Rational DOORS
PDF
XLS PE How To Tutorials Tips & Tricks
DOC
Oracle report from ppt
PPT
Reports 6i
PDF
Oracle9i reports developer
PPT
VB6 Using ADO Data Control
PPT
Oracle D2K reports
PDF
DOCX
synopsis
Responsive Design and Bootstrap
OBIEE publisher with Report creation - Tutorial
Oracle Form material
Generic steps in informatica
Oracle Certification 1Z0-1041 Questions and Answers
Rational Publishing Engine with Rational DOORS
XLS PE How To Tutorials Tips & Tricks
Oracle report from ppt
Reports 6i
Oracle9i reports developer
VB6 Using ADO Data Control
Oracle D2K reports
synopsis
Ad

Viewers also liked (18)

PPT
AM Lunchlezing: Project re:DDS (6 febr 2012)
PDF
Resolucion 1401 de 2007 investigacion accidente de trabajo
PDF
Dr Amir Hannan
PDF
UX Awards: Winning Submissions & Great Case Studies that Tell Stories
PDF
ProventusHR Corporate
PDF
Proyecto Imaginat Alaquas
PDF
NYC-CHI Connected Spaces: NYC IoT Event, September 5, 2013
PPS
Viaje Dajla Ies Mare Nostrum
PDF
Проблематика взаимодействия между исполнителем и заказчиком
PPT
Expansion Of The Cape Town Container Terminal
ZIP
Google Health Architecture & API
PDF
 ZephyrLab Design Studio — Portfolio
PDF
RIW 2016 — Государственные услуги
PPT
Bio mechanical considerations in complete denture prosthesis/ orthodontics india
PPT
Muscles of mastication/ orthodontics courses in india
PDF
Основы рекламы для совсем начинающих
PDF
Дизайн-выходные: Работа с контентом — Серёжа Кузнецов
PPTX
Présentation Lifesize lors du Waycom Business Meeting du 11/06/15 au Peninsula
AM Lunchlezing: Project re:DDS (6 febr 2012)
Resolucion 1401 de 2007 investigacion accidente de trabajo
Dr Amir Hannan
UX Awards: Winning Submissions & Great Case Studies that Tell Stories
ProventusHR Corporate
Proyecto Imaginat Alaquas
NYC-CHI Connected Spaces: NYC IoT Event, September 5, 2013
Viaje Dajla Ies Mare Nostrum
Проблематика взаимодействия между исполнителем и заказчиком
Expansion Of The Cape Town Container Terminal
Google Health Architecture & API
 ZephyrLab Design Studio — Portfolio
RIW 2016 — Государственные услуги
Bio mechanical considerations in complete denture prosthesis/ orthodontics india
Muscles of mastication/ orthodontics courses in india
Основы рекламы для совсем начинающих
Дизайн-выходные: Работа с контентом — Серёжа Кузнецов
Présentation Lifesize lors du Waycom Business Meeting du 11/06/15 au Peninsula
Ad

Similar to Data weave (20)

PPTX
Dataweave 160103180124
PPTX
Data weave
PPTX
Data weave
PPTX
Data weave
PPTX
Data weave
PPTX
Data weave in Mule
PPTX
Data weave
PPTX
Dataweave nagarjuna
PPTX
Mule data weave
PPTX
Dataweave in studio
PPTX
Data weave in mule
PPTX
Mule with data weave
PPTX
Mule dataweave
PPTX
Muledataweave10 161029032456-161119152200
PPTX
PPTX
Data weave documentation
PPTX
Mule data weave_10
PPTX
Mule data weave_2
PDF
MuleSoft DataWeave data transformation language
PPTX
Power of Transformation with DataWeave 2.X Engine
Dataweave 160103180124
Data weave
Data weave
Data weave
Data weave
Data weave in Mule
Data weave
Dataweave nagarjuna
Mule data weave
Dataweave in studio
Data weave in mule
Mule with data weave
Mule dataweave
Muledataweave10 161029032456-161119152200
Data weave documentation
Mule data weave_10
Mule data weave_2
MuleSoft DataWeave data transformation language
Power of Transformation with DataWeave 2.X Engine

More from Khan625 (20)

PPTX
Mapping and listing in mule
PPTX
Message properties component in Mule
PPTX
Jenkins Build System
PPTX
Building and Managing Projects with Maven
PPTX
Web services soap
PPTX
Web services wsdl
PPTX
Web services uddi
PPTX
Web services with soap
PPTX
Maven
PPTX
WebServices Basic Overview
PPTX
Java Basics
PPTX
Mmc rest api user groups
PPTX
Mapping and listing with mule
PPTX
Message properties component in mule
PPTX
Expression filter in Mule
PPT
Anypoint data gateway
PPTX
Mule with drools
PPTX
Mule esb
PPTX
Idempotent filter with simple file
PPTX
Mule with quartz
Mapping and listing in mule
Message properties component in Mule
Jenkins Build System
Building and Managing Projects with Maven
Web services soap
Web services wsdl
Web services uddi
Web services with soap
Maven
WebServices Basic Overview
Java Basics
Mmc rest api user groups
Mapping and listing with mule
Message properties component in mule
Expression filter in Mule
Anypoint data gateway
Mule with drools
Mule esb
Idempotent filter with simple file
Mule with quartz

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Approach and Philosophy of On baking technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
Modernizing your data center with Dell and AMD
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
MYSQL Presentation for SQL database connectivity
NewMind AI Monthly Chronicles - July 2025
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Advanced methodologies resolving dimensionality complications for autism neur...
Approach and Philosophy of On baking technology
The AUB Centre for AI in Media Proposal.docx
Review of recent advances in non-invasive hemoglobin estimation
Unlocking AI with Model Context Protocol (MCP)
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Understanding_Digital_Forensics_Presentation.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding

Data weave

  • 2. Using the DataWeave Transformer  In Anypoint Studio, you can place a Transform Message element in a flow to create transformations using the DataWeave language.  The editor helps you do this by offering intelligent autocomplete suggestions, an output preview that is updated in real time as you make changes.  This generates a .dwl transformation file (or several of them) that stores your code and is packaged with your Mule application.
  • 3.  When adding a Transform Message element to a Mule Flow, it takes the elements from the incoming Mule Message as its inputs. It then performs the necessary actions to produce a Mule message as output for the next element in the flow
  • 4.  The DataWeave Text Editor GUI  The Transform Message element allows you to freely write DataWeave code.  If you click on an instance of the Transform Message element in your flow, its properties editor will be displayed. This editor is divided into three sections:  Input  Transform  Output
  • 5. Input Section In the main tab, a tree view shows the known metadata contents of the incoming Mule Message, allowing you to explore it and know what data is available for using as an input, and how to reference each part of it. If the Mule flow doesn’t expose Metadata about the elements you need from the incoming message, you can manually specify it. To do so, select the element of the input you desire to define, note that the pencil icon at the top right is no longer grayed out. Click this icon to open a new tab in your input section where you can define a sample with the structure of this data.
  • 6. When the input is of JSON or XML types, the sample input contains plain XML or JSON code. When the input is of type POJO or DataWeave, the sample input is written in DataWeave for more simplicity. In these cases the sample DataWeave code is merely a way to display the sample data, not a transformation in itself.
  • 7. Setting Reader Parameters  Some input formats, like CSV, allow you to define a reader with specific properties that make DataWeave parse inputs differently. Select the input element you wish to configure on the tree view of the input section, then click the gear icon.
  • 8. Transform Section  you write the actual DataWeave code that carries out the transform. Notice that changing the type of your output directive changes the output section of the editor. Although DataWeave as a language supports adding input directives and naming these by any name you like, in Studio the elements of the input message are implicitly considered input directives and so they don’t need to be defined in the header.
  • 9. If Studio has any metadata about the components that are upstream or downstream from your Transform Message element at the time when you add the component to your flow, a scaffolding for your DataWeave code is written out automatically, with as much depth as Studio can intelligently deduce. In some cases, this code may be enough to carry out the transformation you need, and no additional coding is needed. Sometimes, all you need to do is fill in the blank spaces in the scaffolding with references to the input fields, other times you may want to carry out more complex operations that involve aggregation, filtering, calculations, defining custom functions, etc and there you must write this out in DataWeave code.
  • 10. Re-scaffolding Once you’ve added the Transform Message element to your flow, any further changes you make to the surrounding message processors and their metadata won’t affect your `.dw`l file. You may still click the Scaffolding button on the top left of the DataWeave properties editor any time you want and have a new scaffolding built, note that this will erase anything you’ve written in the DataWeave body. Doing this won’t affect any directives you defined in your header (except for the output directive). Use this button if you’ve made any changes to elements that come after the Transform Message element on the flow that expose metadata and don’t mind loosing what you’ve already written into the transform’s body.
  • 11. Referencing Existing Transforms Instead of defining a new .dwl file, you can reference an existing one by clicking theData Source button, selecting On File as the source and referencing the correct file.
  • 12. Handling Multiple Outputs A single Transform Message element can give shape to several different components of the output Mule message. Each of these output components must be defined in a separate .dwl file, written out in a separate tab of the Transform section. For example in one tab you may be defining the payload contents, in another those of an outbound property, and these will both be parts of the same output Mule message
  • 13. To add a new output, click the Plus sign at the bottom right of the section:new+output.png[image] A new tab will then appear, there you can specify where in the output Mule message to place the output of this DataWeave transform. In case you’re creating a new variable or property, you must also set a name for it.
  • 14. In the XML editor you can do the same by adding multiple child elements inside thedw:transform- message component. <dw:transform-message> <dw:set-payload resource="classpath:path/transform.dwl"/> <dw:set- variable variableName="myVariable" resource="classpath:path/transform.dwl"/> <dw:set-session-variable variableName="mySessionVariable" resource="classpath:path/transform.dwl"/> </dw:transform-message>
  • 15. Output Section  This section has two tabs, one of them shows you a neat expandable tree view of the output data structure, the other shows you a preview of what the actual output looks like, built from any sample data you provide in the input section. As you make changes in the transport section, notice how the data structure changes. The output of the transformer is made into the selected component of the output mule message. If your transformer has multiple outputs, the Preview tab will display the one corresponding to the currently selected transform.
  • 16. Using DataWeave Language Elsewhere  All components in Mule that support Mule Expression Language also support expressions written in DataWeave Language. To invoke an expression written in DataWeave language, simply invoke the dw() function, the expression will return whatever the transform outputs.  DataWeave expressions defined within this function work just as those defined within a Transform Message element, the only difference is that the output is returned into the expression’s result, wherever it may be.
  • 17.  For example, you can define a custom object and populate it with elements from the payload:  That same expression could be added inside a Logger,  within a MEL expression, to print out its result: dw(myobject:{id:payload.accountid, user:payload.user}) #[`dw(myobject:{id:payload.accountid, user:payload.user})`]