---
schema_version: "1"
id: c54be810538e00fca72ee51a1d0edadeb9be440a98ff9a7a48da83e4d88284e5
title: prependIfMissing
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.4/dw-strings-functions-prependifmissing.md
canonical_url: https://docs.mulesoft.com/dataweave/2.4/dw-strings-functions-prependifmissing
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 3d66d1c5157e30c04f1715f4910cd84755d5a271caa697c6b5b3c0364567cc2d
description: MuleSoft Documentation Site
release: "2.4"
latest: false
---
---
product: DataWeave
version: 2.4
---

# prependIfMissing

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

## prependIfMissing(text: String, prefix: String): String

Prepends the `prefix` to the beginning of the string if the `text` does not already start with that
prefix.

_Introduced in DataWeave version 2.2.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>text</code></p></td><td><p>The input string.</p></td></tr><tr><td><p><code>prefix</code></p></td><td><p>The text to use as prefix.</p></td></tr></tbody></table>

### Example

This example shows how `prependIfMissing` behaves with different inputs and sizes.

#### Source

```DataWeave
%dw 2.0
import prependIfMissing from dw::core::Strings
output application/json
---
{
  "a": prependIfMissing(null, ""),
  "b": prependIfMissing("abc", ""),
  "c": prependIfMissing("", "xyz"),
  "d": prependIfMissing("abc", "xyz"),
  "e": prependIfMissing("xyzabc", "xyz")
}
```

#### Output

```JSON
{
  "a": null,
  "b": "abc",
  "c": "xyz",
  "d": "xyzabc",
  "e": "xyzabc"
}
```

## prependIfMissing(text: Null, prefix: String): Null

Helper function that enables `prependIfMissing` to work with a `null` value.

_Introduced in DataWeave version 2.2.0._
