Nav

Examples: Extracting Data from Common Sources

Extract a Component of the Mule Event

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

Data to extract Anypoint Studio syntax Design Center syntax

Payload

#[payload]

payload

Attribute

#[attributes.<myAttributeName>]

attributes.<myAttributeName>

Variable

To avoid name collisions, you can prepend variables, as shown.

#[<myVariableName>] or #[variables.<myVariableName>]

<myVariableName> or variables.<myVariableName>

Error object

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

#[error]

error

Flow

#[flow]

For the flow name: #[flow.name]

flow

In Design Center, make sure the field you’re writing on is set to accept functions (Fx).

Use Selector Expressions Within a Component

When referencing an array or object, you can use selector expressions to extract specific values from within a data structure.

For the flow name: flow.name Single value (from array or object) #[payload.users]

payload.users

Multiple values (from an array or object)

#[payload.users.*user]

payload.users.*user

Descendants (of an array or object)

The example uses ..<key-name> to extract all descendants of users down to the user name (uname).

#[payload.users..uname]

payload.users..uname

Index (of an array)

The example uses [<index>] to extract the value at index 2.

#[payload.users[2]