Contact Us 1-800-664-9073

On Saturday April 1, 2023, from 9 AM to 2 PM (PDT), content will be unavailable due to scheduled maintenance.

This version of the product has reached End of Life. You can switch to the latest version, or use the version selector in the left navigation.

DataWeave Selectors

DataWeave 2.1 is compatible with Mule 4.1. Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule will reach its End of Life on November 2, 2022, when Extended Support ends.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

DataWeave 2 selectors traverse the structures of objects and arrays and return matching values.

A selector always operates within a context, which can be a reference to a variable, an object literal, an array literal, or the invocation of a DataWeave function.

For examples that use the selectors described below, see Extract Data.

Selector Type Syntax Return Type



Any type of value that belongs to a matching key



Array of values of any matching keys



Array of values of any matching descendant keys

Key-value pair


Object with the matching key



Value of any type at selected array index


[<index> to <index>]

Array with values from selected indexes

XML attribute

@, .@keyName

String value of the selected attribute



String value of the namespace for the selected key

Key present

keyName?, keyName.@type?

Boolean (true if the selected key of an object or XML attribute is present, false if not)

Assert present


String: Exception message if the key is not present



Array or object containing key-value pairs if the DataWeave expression returns true. Otherwise, returns null.



Returns the value of specified metadata for a Mule payload, variable, or attribute. The selector can return the value of class (.^class), encoding (.^encoding), mime type (.^mimeType), media type (.^mediaType), raw (.^raw), and custom (.^myCustomMetadata) metadata. For details, see Extract Data.

Use of Selectors on Content Stored in Variables

All selectors work with the predefined Mule Runtime variables, such as payload and attributes, and with DataWeave variables. For example, assuming a DataWeave variable defined as var myVar = { "id" : "1234", "name" : "somebody" }, the DataWeave expression returns the value of "name", which is "somebody".

You can select Mule event data by using Mule Runtime variables.

Extracted values are handled as a literal values (as opposed to variables, for example) of one of the supported DataWeave value types.

Data to extract Syntax


payload, for example:

If the payload is {"name" : "somebody"}, returns "somebody".

For more on the Mule payload, see Message Payload.



For examples, see Attributes.



To avoid name collisions, you can prepend variables:


For more on Mule variables, see Variables in Mule Apps.

Error object


For information on errors in the flow, you can use #[error.cause].



For the flow name in the Logger: #[]

Note that does not work in some Core components, such as Set Payload and Transform Message.

For more on flows, see Flows and Subflows.

View on GitHub