DataWeave is a language used in Mule to query and transform data. It can be used graphically or with its powerful JSON-like language. The DataWeave header defines directives for the version, inputs/outputs, namespaces, constants, and functions. Directives specify the version, inputs and outputs with their content types, and namespaces. The inputs and outputs can be application/json, application/xml, or other types.
3. DataWeave Features
It can be used in two different ways:
• You can graphically map fields by dragging and dropping them, as
could be done with the deprecated Data Mapper
• Or you can leverage its powerful JSON-like language that’s purposely
built to make writing transformations as fast as possible and highly
maintainable over the long term. It supports a variety of
transformations, from simple one-to-one mappings, to more
elaborate mappings including normalization, grouping, joins,
partitioning, pivoting and filtering.
4. DataWeave-Header
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 '---'.
5. DataWeave-Directives
Through directives you can define:
• 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
6. DataWeave- Version& Namespace Directive
Version Directive:
• Through this directive, you specify the version of the DataWeave syntax
that is used to interpret the transformation.
%dw1.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.
%namespace ns0 http://www.mulesoft.com/anypoint/SOA/message/v1
7. DataWeave-Input & Output Directive
When using DataWeave in Anypoint Studio, it’s not necessary to declare
input directives for any of the components of the Mule Message that arrive
at the DataWeave transformer (Payload, flow variables, and input/outbound
properties) nor for any system variables. These are already implicitly
recognized as inputs and can be referenced anywhere in the DataWeave
body without a need to include them in the header because their type is
known from the Mule metadata.
Inputs are declared by assigning a name and a content type.
%input payload application/xml
Valid types are:
application/json, application/xml, application/java, application/csv,
application/dw, text/json, text/xml, text/csv
8. DataWeave-Input & Output Directive(cont..)
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.
%output application/xml
Valid types are:
application/json, application/xml, application/java, application/csv,
application/dw, text/json, text/xml, text/csv