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

# wrapIfMissing

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

## wrapIfMissing(text: String, wrapper: String): String

Wraps `text` with `wrapper` if that `wrapper` is missing from the start or end of the given string.

_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>wrapper</code></p></td><td><p>The content used to wrap.</p></td></tr></tbody></table>

### Example

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

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Strings
output application/json
---
 {
   "a": wrapIfMissing(null, "'"),
   "b": wrapIfMissing("", "'"),
   "c": wrapIfMissing("ab", "x"),
   "d": wrapIfMissing("'ab'", "'"),
   "e": wrapIfMissing("/", '/'),
   "f": wrapIfMissing("a/b/c", '/'),
   "g": wrapIfMissing("/a/b/c", '/'),
   "h": wrapIfMissing("a/b/c/", '/')
 }
```

#### Output

```JSON
{
   "a": null,
   "b": "'",
   "c": "xabx",
   "d": "'ab'",
   "e": "/",
   "f": "/a/b/c/",
   "g": "/a/b/c/",
   "h": "/a/b/c/"
 }
```

## wrapIfMissing(text: Null, wrapper: String): Null

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

_Introduced in DataWeave version 2.2.0._
