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

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