Contact Free trial Login

DataWeave Selectors

DataWeave 2.0 selectors traverse the structures of objects and arrays and return matching values. Before you begin, note that DataWeave 2.0 is for Mule 4 apps. For a Mule 3 app, refer to the DataWeave 1.0 documentation set in the Mule 3.9 documentation. For other Mule versions, you can use the version selector for the Mule Runtime table of contents.

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), content length (.^contentLength), 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.

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.