A brief Context
Integration Platform, at its core is a transformation engine that should support robust data mapping features and enables streamline communication between different components of connecting systems and processes. Mulesoft, platform traditionally supported mapping tasks with the component architecture and designed a DataMapper as their first pass to data transformation activities. As the platform matured, Mulesoft coupled the transformation engine with Mule runtime to design a elegant and lightweight expression language based on JSON syntax, Dataweave.
Dataweave Environment
Design time capabilities of Dataweave lets you define the message metadata which is automatically detected with Datasense. It also accepts several mime-types set at design time on different message processors and defaults to application /java. Explicitly setting the mime type in variable and payload processor parses the java string into standard content. A simple data mapping file has a header and an expression. Header section specifies the dataweave version & output mime-type and generally mapping is form semi-literal expression of Dataweave Object.
Dataweave Fundus
a) Dataweave not just support simple mappings but address advance transformation usecases like Normalization, Grouping, Joins, Partitioning, Pivots, Filtering.
a) Dataweave expressions can be of simple types like string, boolean, arrays [1,2,3], and objects (key/value pairs). Keys and Values in object can be expressed as expressions that return string literal for key and any expression for a value.
b) payload is a reserved key word that references the incoming data to the transform component and dot operator can be used to access the payload elements which can be array / or other objects.
c) Map operator allows you to iterate through each array element and '$' can be used to reference each element in the array.
d) filter keyword can be used on the payload or after map operator to to transform the desired dataset / or can be used after the transform expression to render the desired results.
e) When operator can be used to support conditional logic which can operate on values of incoming fields.
f) GroupBy operator can be used to aggregate the results based on the value of incoming field. Aggregated record can further iterate over the field array by using the another map operator.
g) Dataweave engine normalizes the variable references to payload, flowVars, sessionVars, recordVars, inboundProperties or outboundProperties to a canonical dataweave format specified with mime type (application/dw) irrespective of mime type of the incoming data.
h) Dataweave Engine separates the rendering process by taking the transformed canonical dataweave format and render it in a output mime type specified in the header.
a) Dataweave expressions can be of simple types like string, boolean, arrays [1,2,3], and objects (key/value pairs). Keys and Values in object can be expressed as expressions that return string literal for key and any expression for a value.
b) payload is a reserved key word that references the incoming data to the transform component and dot operator can be used to access the payload elements which can be array / or other objects.
c) Map operator allows you to iterate through each array element and '$' can be used to reference each element in the array.
d) filter keyword can be used on the payload or after map operator to to transform the desired dataset / or can be used after the transform expression to render the desired results.
e) When operator can be used to support conditional logic which can operate on values of incoming fields.
f) GroupBy operator can be used to aggregate the results based on the value of incoming field. Aggregated record can further iterate over the field array by using the another map operator.
g) Dataweave engine normalizes the variable references to payload, flowVars, sessionVars, recordVars, inboundProperties or outboundProperties to a canonical dataweave format specified with mime type (application/dw) irrespective of mime type of the incoming data.
h) Dataweave Engine separates the rendering process by taking the transformed canonical dataweave format and render it in a output mime type specified in the header.
Expressions
There are 7 basic expressions in dataweave:
a) Literal: "Hello World", [1,2,3], {firstname: "John", lastname: "Doe"}
b) Variable Reference: payload
c) Semi Literal: {people: payload map {name: $.firstname ++ $.lastname}}
d) Selector: lets you navigate to data elements by specifying dot operator on Objects(payload.firstnaname) and index parameters on an array ([1..-1]). You can specify multi key selectors to iterate over the nested object and result in an array.
e) Function Call
f) Flow Invocation
g) Compound: Typically when you use operators along with expression, you end up writing compound expressions to support advanced transformation usecases like iteration, filtering and conditional logic.
a) Literal: "Hello World", [1,2,3], {firstname: "John", lastname: "Doe"}
b) Variable Reference: payload
c) Semi Literal: {people: payload map {name: $.firstname ++ $.lastname}}
d) Selector: lets you navigate to data elements by specifying dot operator on Objects(payload.firstnaname) and index parameters on an array ([1..-1]). You can specify multi key selectors to iterate over the nested object and result in an array.
e) Function Call
f) Flow Invocation
g) Compound: Typically when you use operators along with expression, you end up writing compound expressions to support advanced transformation usecases like iteration, filtering and conditional logic.
Pointers
Integration Platform, at its core is a transformation engine that should support robust
a) https://github.com/madajee/dataweave-2-101.git
b) https://blogs.mulesoft.com/dev/getting-started-with-dataweave-part-1/
c) https://blogs.mulesoft.com/dev/getting-started-with-dataweave-part-2/
a) https://github.com/madajee/dataweave-2-101.git
b) https://blogs.mulesoft.com/dev/getting-started-with-dataweave-part-1/
c) https://blogs.mulesoft.com/dev/getting-started-with-dataweave-part-2/