Presented by
SindhuVL
 The DataWeave Language is a powerful
template engine that allows you to transform
data to and from any kind of format (XML,
CSV, JSON, Pojos, Maps, etc).
 The Header, which defines directives
(optional)
 The Body, which describes the output
structure
 The two sections are delimited by a
separator, which is not required if no header
is present.The separator consists of three
dashes: "---"
 This code describes a conversion from a
JSON input to an XML output:
%dw 1.0
%input application/json
%output application/xml
---
{
user: {
name: payload.user_name,
lastName: payload.user_lastName
}
}
 If Output is other than Json , then just replace
Json to required form like XML, CSV etc. in
the header part :
%input application/json
• Payload attribute is the input data and each
field should be separated by comma :
name: payload.user_name,
lastName: payload.user_lastName
<?xml version="1.0" encoding="UTF-8"?>
<user>
<name> userNameFromPayload </name>
<lastName>
lastNameFromPayload</lastName>
</user>
 The sample output for the example shown
above looks like : (Json format)
{
"user_name": “userNameFromPayload",
"user_lastName": " lastNameFromPayload“
}
 The DataWeave header contains the directives, which
define high level information about your
transformation.The structure of the Header is a
sequence of lines, each with its own Directives.The
Header is terminated with '---'.
 All directives are declared on the header section of
your DataWeave document and act upon the entire
scope of it.
 Directives are a mechanism to declare variables and
constants and namespace aliases which need to be
referenced in the Document.They are also needed to
declare the type of the output of your transform.
 DataWeave version
 Input types and sources
 Output type
 Namespaces to import into your transform
 Constants that can be referenced throughout
the body
 Functions that can be called throughout the
body
VERSION DIRECTIVE :
 Through this directive, you
specify the version of the
DataWeave syntax that is
used to interpret the
transformation.
 coded as : %dw 1.0
NAMESPACE DIRECTIVE :
 This directive associates an
alias with its subsequent
URI.The directive is
relevant only when either
the input or the output is of
type XML.
 Coded as : %namespace
mes
http://www.mulesoft.com
/anypoint/SOA/message/v
1.0
INPUT DIRECTIVE :
 Inputs are declared by
assigning a name and a
content type.You can then
refer to them in any part of
the DataWeave body
through the names defined
in the directive.
 Coded as : %input payload
application/xml
VALID INPUTTYPES ARE :
 application/json
 application/xml
 application/java
 application/csv
 application/dw
 text/json
 text/xml
 text/csv
 When defining an input of type CSV, there are a
few optional parameters you can add to the
input directive to customize how the data is
parsed.These are not defined in the DataWeave
script but on the Mule XML code, in the
Transform Message XML element.
 There are two ways to achieve this :
 Manually add the attributes to the project’s XML
 graphical interface, by selecting the element
from the tree view in the input section and
clicking the gear icon
OUTPUT DIRECTIVE :
 The Output Directive
specifies what the output
type is in a transformation,
which is specified using
content/type. Only one
output can be specified,
the structure of this output
is then defined in the
DataWeave body.
 Coded as :
%output application/xml
VALID OUTPUTTYPES ARE :
 application/json
 application/xml
 application/java
 application/csv
 application/dw
 text/json
 text/xml
 text/csv
 Whenever the output is of XML or JSON type and has null values in
its elements or attributes, you can specify whether this generates
an outbound message that contains fields with "null" values, or if
these fields are ignored entirely.This can be set through an
attribute in the output directive named skipNullOn, which can be
set to three different values: elements, attributes,
or everywhere.
 Like : %output application/xml skipNullOn="everywhere“
When set to:
 elements: A key:value pair with a null value is ignored.
 attributes: An XML attribute with a null value is skipped.
 everywhere: Apply this rule to both elements and attributes.
 DataWeave uses three basic data types: Objects,
Arrays, and SimpleTypes, the execution of a
DataWeave transformation always produces one
of these three types of data.
 This expression can be built using any of the
following elements:
 Objects
 Arrays
 Simple literals
 Variable and Constant references
 Input
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
%dw 1.0
%output application/dw
---
payload
Output :
{
note: {
to: "Tove",
from: "Jani",
heading: "Reminder",
body: "Dont forget me this weekend!“
}
}
ThankYou!!!!!!!!

Data weave component

  • 1.
  • 2.
     The DataWeaveLanguage is a powerful template engine that allows you to transform data to and from any kind of format (XML, CSV, JSON, Pojos, Maps, etc).
  • 3.
     The Header,which defines directives (optional)  The Body, which describes the output structure  The two sections are delimited by a separator, which is not required if no header is present.The separator consists of three dashes: "---"
  • 4.
     This codedescribes a conversion from a JSON input to an XML output: %dw 1.0 %input application/json %output application/xml --- { user: { name: payload.user_name, lastName: payload.user_lastName } }
  • 5.
     If Outputis other than Json , then just replace Json to required form like XML, CSV etc. in the header part : %input application/json • Payload attribute is the input data and each field should be separated by comma : name: payload.user_name, lastName: payload.user_lastName
  • 6.
    <?xml version="1.0" encoding="UTF-8"?> <user> <name>userNameFromPayload </name> <lastName> lastNameFromPayload</lastName> </user>
  • 7.
     The sampleoutput for the example shown above looks like : (Json format) { "user_name": “userNameFromPayload", "user_lastName": " lastNameFromPayload“ }
  • 8.
     The DataWeaveheader contains the directives, which define high level information about your transformation.The structure of the Header is a sequence of lines, each with its own Directives.The Header is terminated with '---'.  All directives are declared on the header section of your DataWeave document and act upon the entire scope of it.  Directives are a mechanism to declare variables and constants and namespace aliases which need to be referenced in the Document.They are also needed to declare the type of the output of your transform.
  • 9.
     DataWeave version Input types and sources  Output type  Namespaces to import into your transform  Constants that can be referenced throughout the body  Functions that can be called throughout the body
  • 10.
    VERSION DIRECTIVE : Through this directive, you specify the version of the DataWeave syntax that is used to interpret the transformation.  coded as : %dw 1.0 NAMESPACE DIRECTIVE :  This directive associates an alias with its subsequent URI.The directive is relevant only when either the input or the output is of type XML.  Coded as : %namespace mes http://www.mulesoft.com /anypoint/SOA/message/v 1.0
  • 11.
    INPUT DIRECTIVE : Inputs are declared by assigning a name and a content type.You can then refer to them in any part of the DataWeave body through the names defined in the directive.  Coded as : %input payload application/xml VALID INPUTTYPES ARE :  application/json  application/xml  application/java  application/csv  application/dw  text/json  text/xml  text/csv
  • 12.
     When definingan input of type CSV, there are a few optional parameters you can add to the input directive to customize how the data is parsed.These are not defined in the DataWeave script but on the Mule XML code, in the Transform Message XML element.  There are two ways to achieve this :  Manually add the attributes to the project’s XML  graphical interface, by selecting the element from the tree view in the input section and clicking the gear icon
  • 13.
    OUTPUT DIRECTIVE : The Output Directive specifies what the output type is in a transformation, which is specified using content/type. Only one output can be specified, the structure of this output is then defined in the DataWeave body.  Coded as : %output application/xml VALID OUTPUTTYPES ARE :  application/json  application/xml  application/java  application/csv  application/dw  text/json  text/xml  text/csv
  • 14.
     Whenever theoutput is of XML or JSON type and has null values in its elements or attributes, you can specify whether this generates an outbound message that contains fields with "null" values, or if these fields are ignored entirely.This can be set through an attribute in the output directive named skipNullOn, which can be set to three different values: elements, attributes, or everywhere.  Like : %output application/xml skipNullOn="everywhere“ When set to:  elements: A key:value pair with a null value is ignored.  attributes: An XML attribute with a null value is skipped.  everywhere: Apply this rule to both elements and attributes.
  • 15.
     DataWeave usesthree basic data types: Objects, Arrays, and SimpleTypes, the execution of a DataWeave transformation always produces one of these three types of data.  This expression can be built using any of the following elements:  Objects  Arrays  Simple literals  Variable and Constant references
  • 16.
     Input <?xml version="1.0"encoding="UTF-8"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 17.
    %dw 1.0 %output application/dw --- payload Output: { note: { to: "Tove", from: "Jani", heading: "Reminder", body: "Dont forget me this weekend!“ } }
  • 18.