DataWeave Operators in Mule3
  • Use map on an Array
    (':array', ':function') ⇒ :array
    Returns an array that is the result of applying a transformation function (lambda) to each of the elements. 
    The lambda is invoked with two parameters: index and the value. If these parameters are not named, the index is defined by default as $$ and the value as $.

  • Use map on an Object
    (':object', ':function') ⇒ ':array'
    Returns an array with the values that result out of applying a transformation function (lambda) to each of the values in the object. 
    The keys of the original object are all ignored by this operation and the object is treated as an array.

(':object', ':function') ⇒ ':object'
Similar to map, but instead of processing only the values of an object, it processes both keys and values as a tuple. 
Also instead of returning an array with the results of processing these values through the lambda, it returns an object, which consists of a list of the key:value pairs that result from processing both key and value of the object through the lambda.

(':object', ':function') ⇒ ':array'
pluck is useful for mapping an object into an array.
pluck is an alternate mapping mechanism to mapObject
Like mapObject, pluck executes a lambda over every key:value pair in its processed object as a tuple, but instead of returning an object, it returns an array, which may be built from either the values or the keys in the object.

  • Use filter on an Array
    (':array', ':function') ⇒ ':array'
    Returns an array that is the result of applying a transformation function (lambda) to each of the elements. 
    The lambda is invoked with two parameters: index and the value. If these parameters are not named, the index is defined by default as $$ and the value as $.

  • Use filter on an Object
    (':object', ':function') ⇒ ':object'
    Returns an object with the key:value pairs that pass the acceptance criteria defined in the lambda.
    If these parameters are not named, the index is defined by default as $$ and the value as $.

  • Use Remove on an Array
    (':array', ':name') ⇒ ':array'
    When running it on an array, it returns another array where the specified names are removed.

  • Use Remove on an Object
    (':object', ':name') ⇒ ':object'
    When running it on an object, it returns another object where the specified keys are removed.

  • Use Remove on Matching Key and Value
    (':object', ':object') ⇒ ':object'
    Works just like remove on objects, but only removes an element when there is a match of not just the key but of the key + value pair .
    It returns another object where the specified keys are removed.

The expression and (in lower case) can be used to link multiple conditions


The expression or (in lowercase) can be used to link multiple conditions.
Its use means that either one or all of the linked conditions must evaluate to true for the expression as a whole to evaluate to true


(':any', condition) ⇒ ':boolean'
Evaluates if a condition validates to true and returns a boolean value.


The concat operator is defined using double plus signs. You must have spaces on both sides of them.
  • Use concat on an Array
    (':array', ':array') ⇒ ':array'
    When using arrays, it returns the resulting array of concatenating two existing arrays.

  • Use Concat on an String
    (':string', ':string') ⇒ ':string'
    Strings are treated as arrays of characters, so the operation works just the same with strings.

  • Use concat on an Object
    (':object', ':object') ⇒ ':object'
    Returns the resulting object of concatenating two existing objects.

Evaluates if an array or list contains in at least one of its indexes a value that validates to true and returns a boolean value
  • Use contains on an Array
    (':array', ':any') ⇒ ':boolean'
    We can evaluate if any value in an array matches a given condition:

  • Use contains on an String
    (':string', ':regex') ⇒ ':boolean'
    can also use contains to evaluate a substring from a larger string:


Check the type coercion table to see what conversions between what types are allowed in DataWeave.
  • Coerce to string
    (':any', ':type') ⇒ ':string'
    Any simple types can be coerced to string. If formatting is required (such as for a number or date) the format schema property can be used.

  • Coerce to number
    (':string', ':type') ⇒ ':number'
    A string can be coerced to number. If the given number has a specific format the schema property can be used.

  • Coerce a date to number
    (':time', ':type') ⇒ ':number'
    When coercing a date to a number, there is an extra parameter you can add – 'unit' – to specify what unit of time to use,

  • Coerce to date
    (':string', ':type')/(':number', ':type') ⇒ ':date'
    Date types can be coerced from string or number.

  • Coerce to Object
    (':any', ':type') ⇒ ':object'
    We can coerce our input into a custom object type of whatever class you want.


(':any') ⇒ ':type'
Returns the type of a provided element (eg: '":string"' , '":number"' )

(':array') ⇒ ':array'
If you have an array of arrays, this function can flatten it into a single simple array.

(':array')/(':string')/(':object') ⇒ ':number'
Returns the number of elements in an array (or anything that can be converted to an array such as a string).

(:array', ':any') ⇒ ':array'
Pushes a new element to the end of an array.

(:array', ':any') ⇒ ':array'
Removes an element from an array when it matches the specified value.
If multiple elements in the array match the value, they will all be removed.

(':array', ':array') ⇒ ':array'
Removes a set of elements from an array when an element in the base array matches one of the values in the substracted array.
If multiple elements in the array match the value, they will all be removed.

(':array') ⇒ ':number'
Creates an average of all the values in an array and outputs a single number.
The array must of course contain only numerical value in it.

(':array', ':function') ⇒ ':any'
Apply a reduction to the array using just two parameters: the accumulator ($$), and the value ($).
By default, the accumulator starts at the first value of the array.

In some cases, you may not want to use the first element of the array as an accumulator.
To set the accumulator to something else, you must define this in a lambda.

(':array', ':string') ⇒ ':string'
Merges an array into a single string value, using the provided string as a separator between elements.
By default, the accumulator starts at the first value of the array.

(':string', ':string')/(':string', ':regex') ⇒ ':array'
Performs the opposite operation as Join By.
It splits a string into an array of separate elements, looking for instances of the provided string and using it as a separator.

(':array', ':function')/(':object', ':function') ⇒ ':array'/':object'
Returns the provided array (or object) ordered according to the value returned by the lambda.
The lambda is invoked with two parameters: index and the value.
If these parameters are not named, the index is defined by default as $$ and the value as $.

(':array', ':function') ⇒ ':object'
Partitions an array into a Object that contains Arrays, according to the discriminator lambda we define.
The lambda is invoked with two parameters: index and the value.
If these parameters are not named, the index is defined by default as $$ and the value as $.

(':array', ':function') ⇒ ':array'
Returns only unique values from an array that may have duplicates.
The lambda is invoked with two parameters: index and the value.
If these parameters are not named, the index is defined by default as $$ and the value as $.

(':array', ':array') ⇒ ':array'
Given two or more separate lists, the zip function can be used to merge them together into a single list of consecutive n-tuples.
the zip function interdigitates each element from each input list, one element at a time.

(':array') ⇒ ':array'
Performs the opposite function of zip arrays.
the zip function interdigitates each element from each input list, one element at a time.
Given a single array where each index contains an array with two elements, it outputs two separate arrays.

(':string', ':regex', ':function') ⇒ ':string'
Replaces a section of a string for another, in accordance to a regular expression, and returns a modified string.

(':string', ':regex') ⇒ ':boolean'
Matches a string against a regular expression, and returns true or false.

(':string', ':string') ⇒ ':boolean'
Returns true or false depending on if a string starts with a provided substring.

(':string', ':string') ⇒ ':boolean'
Returns true or false depending on if a string ends with a provided substring.

(':string', ':string')/.(':string', ':regex') ⇒ ':array'
It returns the index position within the string at which a match was matched.
If found in multiple parts of the string, it returns an array with the various index positions at which it was found

(':string', ':regex') ⇒ ':array'
Match a string against a regular expression.
Match returns an array that contains the entire matching expression, followed by all of the capture groups that match the provided regex.
It can be applied to the result of any evaluated expression, and can return any evaluated expression.

(':string', ':regex') ⇒ ':array'
Returns an array with all of the matches in the given string.
Each match is returned as an array that contains the complete match, as well as any capture groups there may be in your regular expression.

(':any', ':any') ⇒ ':boolean'
Evaluates if two values are similar, regardless of their type.
For example, the string "1234" and the number 1234 aren’t equal, but they are recognised as similar.

(':string') ⇒ ':string'
Returns the provided string in uppercase characters.

(':string') ⇒ ':string'
Returns the provided string in lowercase characters.

(':string') ⇒ ':string'
Returns the provided string in camel case.
All underscores are deleted, including any underscores at the beginning of the string.

(':string') ⇒ ':string'
Returns the provided string with every word starting with a capital letter and no underscores.
It also replaces underscores with spaces and puts a space before each capitalized word.

(':string') ⇒ ':string'
Returns the provided string with every word separated by a dash.

(':string') ⇒ ':string'
Returns the provided string with every word separated by an underscore.

(':string') ⇒ ':string'
Returns the provided string transformed into its plural form.

(':string') ⇒ ':string'
Returns the provided string transformed into its plural form.

(':string') ⇒ ':string'
Removes any excess spaces at the start and end of a string.

(':string') ⇒ ':string'
Extracts a set of characters out of a string, based on the position that the first and last character of the desired substring occupy in the character array.
If we use negative numbers, you can also inverse the order in which characters are set.

(':number') ⇒ ':string'
Returns the provided numbers set as ordinals.





(':array')/(':object') ⇒ ':number'
Returns the highest number in an array or object.

(':array')/(':object') ⇒ ':number'
Returns the lowest number in an array or object.

(':number') ⇒ ':number'
Rounds the value of a number to the nearest integer.

(':number') ⇒ ':number'
Returns the square root of the provided number.

(':number', ':number') ⇒ ':number'
Returns the result of the first number a to the power of the number following the pow operator.

(':number') ⇒ ':number'
Rounds a number upwards, returning the first full number above than the one provided.

(':number') ⇒ ':number'
Rounds a number downwards, returning the first full number below than the one provided.

(':number') ⇒ ':number'
Returns the absolute value of a number.

(':number', ':number') ⇒ ':number'
Returns the remainder after division of the first number by the second one

Returns a datetime object with the current date and time.

(':date')/(':time')/(':localtime')/(':datetime')/(':localdatetime')/(':period') ⇒ (':date')/(':time')/(':localtime')/(':period')
We can extract a particular time unit from any date related type as shown below:

(':datetime', ':timezone') ⇒ ':datetime'
Shift a date time to the specified timezone.

(':date', ':time')/(':date', ':localtime')/(':time', ':date')/(':localtime', ':date') ⇒ (':localtime')/(':datetime')/(':localdatetime')

(':datetime', ':timezone')/(':time', ':timezone')/(':localtime', ':timezone')/(':localdatetime', ':timezone') ⇒ (':localtime')/(':localdatetime')
Appends a time zone to a date type value.

(':time', ':period')/(':datetime', ':period')/(':localtime', ':period')/(':localdatetime', ':period') ⇒ (':date')/(':time')/(':localtime')/(':datetime')/(':localdatetime')
Add or subtract a period of time from a given date or time type object.

(':time', ':period')/(':datetime', ':period')/(':localtime', ':period')/(':localdatetime', ':period') ⇒ (':date')/(':time')/(':localtime')/(':datetime')/(':localdatetime')
The same logically applies to subtracting time periods from a date or time type object.

(':date', ':date')/(':datetime', ':datetime')/('#:time', ':time')/(':localtime', ':localtime')/(':localdatetime', ':localdatetime') ⇒ ':period'
When subtracting one date or time type object from another, what we logically get is the difference between these times expressed as a time period.

If you got some knowledge about DataWeave Operators, please follow with me in next topic to understand about API-led Architecture.

Comments