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

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