then(value: Null, callback: (previousResult: Nothing) -> Any): Null

Helper function that enables then to work with a null value.

Introduced in DataWeave version 2.4.0.

then<T, R>(previous: T, callback: (result: T) -> R): R

This function works as a pipe that passes the value returned from the preceding expression to the next (a callback) only if the value returned by the preceding expression is not null.

Introduced in DataWeave version 2.4.0.


Name Description


The value of the preceding expression.


Callback that processes the result of previous if the result is not null.


This example shows how to use then to chain and continue processing the result of the previous expression.


%dw 2.0
output application/json
    "chainResult": ["mariano", "de Achaval"]
            reduce ((item, accumulator) -> item ++ accumulator)
            then ((result) -> sizeOf(result)),
    "referenceResult" : ["mariano", "de Achaval"]
                         map ((item, index) -> upper(item))
                         then {
                            name: $[0],
                            lastName: $[1],
                            length: sizeOf($)
    "onNullReturnNull": []
                reduce ((item, accumulator) -> item ++ accumulator)
                then ((result) -> sizeOf(result))


   "chainResult": 17,
   "referenceResult": {
     "name": "MARIANO",
     "lastName": "DE ACHAVAL",
     "length": 2
   "onNullReturnNull": null

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Submit your feedback!
Share your thoughts to help us build the best documentation experience for you!
Take our latest survey!