---
schema_version: "1"
id: 51f4eb344994142ee9a811d9a12aa7dad1fc98f88af3bac409af8ed714583027
title: leftPad
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.12/dw-strings-functions-leftpad.md
canonical_url: https://docs.mulesoft.com/dataweave/2.12/dw-strings-functions-leftpad
source_site: docs.mulesoft.com
content_type: documentation
content_hash: c38b108103cd38b74aa99fe4d1bc9e1e561ef694764748d96f42d6ce7f20b6c7
description: MuleSoft Documentation Site
release: "2.12"
latest: false
---
---
product: DataWeave
version: 2.12
---

# leftPad

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

## leftPad(text: String, size: Number, padText: String = " "): String

The specified `text` is _left_\-padded to the `size` using the `padText`. By default `padText` is
`" "`.

Returns left-padded `String` or original `String` if no padding is necessary.

_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>size</code></p></td><td><p>The size to pad to.</p></td></tr><tr><td><p><code>padText</code></p></td><td><p>The text to pad with. It defaults to one space if not specified.</p></td></tr></tbody></table>

### Example

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

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Strings
output application/json
---
{
   "a": leftPad(null, 3),
   "b": leftPad("", 3),
   "c": leftPad("bat", 5),
   "d": leftPad("bat", 3),
   "e": leftPad("bat", -1)
}
```

#### Output

```JSON
{
  "a": null,
  "b": "   ",
  "c": "  bat",
  "d": "bat",
  "e": "bat"
}
```

## leftPad(text: Null, size: Any, padText: Any = " "): Null

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

_Introduced in DataWeave version 2.2.0._
