---
schema_version: "1"
id: 9dd36ad45ac122d36b1b71678d52e92d2f138d7ce2ce36f9a6fe29a62632f294
title: Migrating from DataWeave version 1 to 2
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-runtime/4.4/migration-dataweave.md
canonical_url: https://docs.mulesoft.com/mule-runtime/4.4/migration-dataweave
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 8849a3cde518caa61231d2470f711114681965c75ec8b6be34cad28d39a18b6a
description: MuleSoft Documentation Site
release: "4.4"
latest: false
---
---
product: Mule Runtime
version: 4.4
---

# Migrating from DataWeave version 1 to 2

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

- [DataWeave Header Content](#dw_header)

- [Flow Controls](#dw_flow_control)

- [Type References](#dw_type_references)

- [Object Coercion](#dw_object_coercion)

- [Conditional Key-Value Parenthesis](#dw_cond_key_value_parens)

## DataWeave Header Content

Most of the header directives have been changed in DataWeave. The `%dw` directive is an exception.
In most cases, MuleSoft removed the `%`, and in some cases the keyword is shortened.

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>DataWeave 1.0</th><th>DataWeave 2.0</th><th>Comments</th></tr></thead><tbody><tr><td><div><div><p><code>%dw 1.0</code></p></div></div></td><td><div><div><p><code>%dw 2.0</code></p></div></div></td><td><div></div></td></tr><tr><td><div><div><p><code>%input</code></p></div></div></td><td><div><div><p><code>input</code></p></div></div></td><td><div><div><p>In a Mule app flow, DataWeave 2.0 recognizes the input MIME type and its reader properties based on the MIME type (<code>outputMimeType</code>) and parameters specified in the preceding component. The input MIME type is not defined using the <code>input</code> directive in the header anymore. However, the <code>input</code> directive is still used in specific cases like <a href="https://docs.mulesoft.com/dataweave/latest/dataweave-streaming#validate-a-script-for-streamed-data-experimental-feature">Validate a Script for Streamed Data</a>.</p></div></div></td></tr><tr><td><div><div><p><code>%output</code></p></div></div></td><td><div><div><p><code>output</code></p></div></div></td><td><div></div></td></tr><tr><td><div><div><p><code>%var</code></p></div></div></td><td><div><div><p><code>var</code></p></div></div></td><td><div></div></td></tr><tr><td><div><div><p><code>%function</code></p></div></div></td><td><div><div><p><code>fun</code></p></div></div></td><td><div></div></td></tr><tr><td><div><div><p><code>%namespace</code></p></div></div></td><td><div><div><p><code>ns</code></p></div></div></td><td><div></div></td></tr></tbody></table>

## Flow Controls

Flow control changed somewhat in DataWeave 2.

### When Otherwise

The `when otherwise` statement is replaced by `if else`, for example:

Mule 3 Example: DataWeave 1

```dataweave
{
    orderStatus: "complete" when flowVars.purchaseOrderStatus == "C" otherwise "incomplete"
}
```

Mule 4 Example: DataWeave 2

```dataweave
{
    orderStatus: if(vars.purchaseOrderStatus == "C") "complete" else "incomplete"
}
```

### Pattern Matcher

Pattern matching changed in DataWeave 2. It adds the keyword `case` and `else` (instead of
`default`). You also no longer separate cases with commas (`,`) since they are now explicitly
separated by the `case` keyword.

Mule 3 Example: DataWeave 1

```dataweave
'world' match {
    :string -> true,
    default -> false
  }
```

Mule 4 Example: DataWeave 2

```dataweave
'world' match {
    case is String -> true
    else -> false
  }
```

For type pattern matchers, the `is` keyword needs to be set.

## Type References

The `:` was removed from the type references and are now all camel case, so `:string` is now
`String`

## Object Coercion

In DataWeave 1.0, selecting a key-value pair from an object required you to do something like this:

Mule 3 Example: DataWeave 1

```dataweave
%var payload = {a: 1, b:2}
---
payload.a as :object
```

The DataWeave 1.0 expression above returns `{a:1}`. Because this is a coercion, it is also included
in the auto-coercion mechanism and generates undesired or unexpected results.

In DataWeave 2.0, the coercion is removed, and a new selector (`&`) is introduced to select
key-value pair parenthesis.

Mule 3 Example: DataWeave 2

```dataweave
var payload = {a: 1, b:2}
---
payload.&a
```

This expression also returns `{a:1}`.

## Conditional Key-Value Parenthesis

In DataWeave 1.0, conditional key-value pairs are declared with the `when` keyword.

Mule 3 Example: DataWeave 1

```dataweave
{
    (a: 1) when payload.product == "Mule"
}
```

In DataWeave 2.0, you use the `if` keyword.

Mule 4 Example: DataWeave 2

```dataweave
{
    (a: 1) if payload.product == "Mule"
}
```

## See Also

[Introduction to Mule 4: DataWeave 2.0](https://docs.mulesoft.com/mule-runtime/4.4/intro-dataweave2)
