Get Started with DataWeave


DataWeave is a default data transformation language for Mule. It came a long way since its v1 inception in Mule 3 release and v2 with Mule 4 release. Recently, DataWeave started its journey to become an open-source data transformation language. So, where can you start your data transformations with DataWeave? Let’s explore options.

The first logical step to start your DataWeave journey should be checking out the DataWeave reference documentation. However, if you are new to the DataWeave, that might be overwhelming. Let’s see if we can find a path for getting started with the DataWeave.

1. Basics

1.1 Interactive Tutorial

Online DataWeave Tutorial provides you with a guided and interactive journey into understanding as well as exploring the basics of DataWeave. It does not need adding any dependency to your system except requiring just a browser and the internet to get started.

Here you can follow the path and examples provided to explore and learn the DataWeave language. It nicely explains some basic concepts and provides you some exercises to perform. This can be a great way to start your journey.

mule dataweave get started tutotial 1
Figure 1. DataWeave Online Tutorial

1.2 Documentation

Assuming that you have followed that interactive tutorial and now have an idea of what DataWeave is, the next thing can be to read more about what DataWeave can do. The extensive reference documentation of DataWeave may be the right next step to look at.

The documentation can guide you through all the features and modules supported in DataWeave. It also provides a lot of example transformations to try and strengthen your DataWeave understanding.

2. Tools

In next sections, we will learn about some tools available for working with DataWeave scripts. You can even choose more than one to continue on your DataWeave journey.

2.1 Online Playground

The best and quick way to play with DataWeave is, to use DataWeave Playground!

DataWeave Playground is an online DataWeave editor and has some great capabilities. It supports many input data formats and lets you write your data transformations and preview them.

In addition to scripting capabilities, it also includes DataWeave API Reference documentation.

Using this does not need any dependency except an internet-enabled web browser.

You can easily play with your own data examples and data transformations.

mule dataweave get started playground 1
Figure 2. DataWeave Online Playground

2.2 Anypoint Studio

Anypoint Studio is MuleSoft provided IDE for developing Mule applications. If you are planning to be a Mule Developer and use DataWeave in your Mule applications, you can install Anypoint Studio.

DataWeave being a default transformation language for Mule, Anypoint Studio has inbuilt support for writing DataWeave transformations.

Mule has a component called "Transform Message" that allows you to write DataWeave transformations and execute them at runtime. Anypoint Studio provides an editor for the Transform component that lets you build and preview your data transformation script with example payloads.

mule dataweave get started studio 1
Figure 3. Anypoint Studio - Transform Message component

2.3 DataWeave Extension - VS Code

If you are a Visual Studio Code user and likes to be in it, you can use a DataWeave Extension (BETA) for VS Code.

This extension allows you to develop, debug, preview and test DataWeave scripts. You can even build libraries of DataWeave scripts that can be shared with other applications. It has a full SDLC support for DataWeave libraries.

mule dataweave get started vscode 1
Figure 4. DataWeave Extension - VS Code

2.4. DataWeave CLI

DataWeave CLI is another great utility to explore for using DataWeave. If you like to transform data on the command line or work with data transformations on the fly in your command line, you may want to check this option.

This can be pretty useful for any data analysis/transformation use cases, including not involving mule applications at all.

Here are examples of what you can do with CLI -

Example 1: Processing Remote API Response
 $ http  https://random-data-api.com/api/v2/users\?size\=10 | dw "payload.id" (1)

[
  5855,
  4154,
  1783,
  9191,
  1235,
  5942,
  4981,
  5719,
  7843,
  6009
]
1 Reads random data from an API and pipes the output into DataWeave CLI to just extract usernames from the response.
Example 2: Processing local files with data transformation
$ dw -i payload users.json "(payload filter (user) -> user.gender == 'Male') map (user) -> user.id "  (1)

[
  3646
]
1 Reading a local file, filter records and extract ids

4. References

5. Conclusion

In this article, we looked at ways to get started with learning DataWeave. There are reference and tools available but in addition to that there is a Mule community out there to help at Forum, Stackoverflow. Happy learning and transforming!

on twitter to get updates on new posts.

Stay updated!

On this blog, I post articles about different technologies like Java, MuleSoft, and much more.

You can get updates for new Posts in your email by subscribing to JavaStreets feed here -


Lives on Java Planet, Walks on Java Streets, Read/Writes in Java, JCP member, Jakarta EE enthusiast, MuleSoft Integration Architect, MuleSoft Community Ambassador, Open Source Contributor and Supporter, also writes at Unit Testers, A Family man!