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

# 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._
