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.
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 |
---|---|---|
Single-value |
|
Any type of value that belongs to a matching key |
Multi-value |
|
Array of values of any matching keys |
Descendants |
|
Array of values of any matching descendant keys |
Key-value pair |
|
Object with the matching key |
Index |
|
Value of any type at selected array index |
Range |
|
Array with values from selected indexes |
XML attribute |
|
String value of the selected attribute |
Namespace |
|
String value of the namespace for the selected key |
Key present |
|
Boolean ( |
Assert present |
|
String: Exception message if the key is not present |
Filter |
|
Array or object
containing key-value pairs if the DataWeave expression returns |
Metadata |
|
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
myVar.name
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 |
If the For more on the Mule payload, see Message Payload. |
Attribute |
For examples, see Attributes. |
Variable |
To avoid name collisions, you can prepend
For more on Mule variables, see Variables in Mule Apps. |
Error object |
For information on errors in the flow, you can use |
Flow |
For the flow name in the Logger: Note that For more on flows, see Flows and Subflows. |