---
schema_version: "1"
id: 4b75eaefdedf996187beb28208b22aeaba0c952e7de1f22c6abe5341aee40c9d
title: onNull
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dw-core-functions-onnull.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dw-core-functions-onnull
source_site: docs.mulesoft.com
content_type: documentation
content_hash: cb6fd10aaf75e588a9cbda01b063ccbb7c6ca850390bb907d5c9348cc3e9dd86
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
---

# onNull

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## onNull<R>(previous: Null, callback: () -> R): R

Executes a callback function if the preceding expression returns a `null` value and then replaces
the `null` value with the result of the callback.

_Introduced in DataWeave version 2.4.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>previous</code></p></td><td><p>The value of the preceding expression.</p></td></tr><tr><td><p><code>callback</code></p></td><td><p>Callback that generates a new value if <code>previous</code> returns <code>null</code>.</p></td></tr></tbody></table>

### Example

This example shows how `onNull` behaves when it receives a `null` value.

#### Source

```DataWeave
%dw 2.0
output application/json
---
{
     "onNull": []
             reduce ((item, accumulator) -> item ++ accumulator)
             then ((result) -> sizeOf(result))
             onNull "Empty Text"
 }
```

#### Output

```Json
{
  "onNull": "Empty Text"
}
```

## onNull<T>(previous: T, callback: () -> Any): T

Helper function that enables `onNull` to work with a _non-null_ value.

_Introduced in DataWeave version 2.4.0._
