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

# wrapIfMissing

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

## wrapIfMissing(String, String): String

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

_Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later._

### 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(Null, String): Null

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