DataWeave – Transformations Made Easy

07.09.2015

DataWeave is a new language for querying and transforming data. DataWeave includes a connectivity layer and engine that is fundamentally different from other transformation technologies. It contains a data access layer that indexes content and accesses the binary directly, without costly conversions, enabling larger than memory payloads, random access to input documents and very high performance.

We have taken a simple file transformation and set off data as an example that is to be transformed from JSON to XML.

The flow below shows the file to file transformation and mapping created for showcasing the DataWeave. The transformation component is called ‘Transform Message’, when we look at the component pallet in Anypoint Studio. We will not see any component as DataWeave.

data weave flow

When the transform message component is selected, we can see the properties as shown below.

data weave properties

The above image shows three sections, the first one is an input section which shows the message section and what is available for transformation. The second section is the DataWeave code and the third one output section that shows us the preview of the transformation in the expected output format.

DataWeave code is a JSON like syntax and is format neutral. This is used to define the mappings. The top section defines the output, variables and the expected structure. Under that, we have the code after the three hyphens. These three hyphens are expected by the DataWeave engine to understand where the transformation actually starts.

The output section is instantly updated and we can see the updates as we are making the changes to the mapping in the code section.

In the above example we have use the output type ‘application/xml’, as defined in the top section in the code, so our output is in XML format. The format for output can be changed to csv or java by just changing the output type to   ‘application/csv’. The change can also be observed in the output section as shown below.

data weave properties

or to ‘application/java’ as shown below.

data weave properties

The DataWeave language has lot of operators like functions, operators, filters, etc. built into it to help with most of the common transformations. It also supports a variety of transformations, from simple one-to-one mappings to more elaborate mappings including normalization, grouping, joins, deduplication and pivoting. It also supports XML, JSON, CSV, Java and EDI out of the box. The comprehensive reference documentation is available for full list.

NOTE: currently, reading larger than memory XML is not yet supported.

Overall DataWeave makes the transformations easy to develop. It also isolates the input and the output types, which can be changed even after creation of the transformation provided the formatting and element mappings remain the same. The DataWeave universal language for data access can not only be used for transformation, but also for querying data throughout your flow. Using the dw() function, we can quickly query data and use it to log information from payloads, route data, or extract it for message enrichment.

If you would like to find out more about how Systems Integration could help you make the most out of your current infrastructure while enabling you to open your digital horizons, do give us a call at +44 (0)203 475 7980 or email us at marketing@whishworks.com

Other useful links:

5 + 1 must have technologies for eCommerce success

APIs in the IoT

EDI to API – The evolution of systems integration, Part 1

Recent Posts