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

# leftPad

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

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

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