---
schema_version: "1"
id: fc42eecb927a839ef62a4703f4a124ca053d58e2708ef3d4d8d03fcc3d4cfc97
title: encodeURIComponent
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-url-functions-encodeuricomponent.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-url-functions-encodeuricomponent
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 31e896acb007bb4003e12100849c3f9ef8942795a657e90e987fb63f7738f53e
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# encodeURIComponent

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

## encodeURIComponent(text: String): String

Escapes certain characters in a URI component using UTF-8 encoding.

There can be only four escape sequences for characters composed of two "surrogate" \* characters.
`encodeURIComponent` escapes all characters _except the following_: alphabetic, decimal digits,
`- _ . ! ~ * ' ( )`. Note that `encodeURIComponent` differs from `encodeURI` in that it encodes
reserved characters and the Number sign `#` of `encodeURI`:

<table><colgroup><col> <col></colgroup><thead><tr><th>Type</th><th>Includes</th></tr></thead><tbody><tr><td><p>Reserved characters</p></td><td></td></tr><tr><td><p>Unescaped characters</p></td><td><p>alphabetic, decimal digits, - _ . ! ~ * ' ( )</p></td></tr><tr><td><p>Number sign</p></td><td></td></tr></tbody></table>

### 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>URI component string.</p></td></tr></tbody></table>

### Example

This example encodes a variety of URI components.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::URL
output application/json
---
{
  "comparing_encode_functions_output" : {
  	"encodeURIComponent" : encodeURI(" PATH/ TO /ENCODE "),
  	"encodeURI" : encodeURI(" PATH/ TO /ENCODE "),
  	"encodeURIComponent_to_hex" : encodeURIComponent(";,/?:@&="),
  	"encodeURI_not_to_hex" : encodeURI(";,/?:@&="),
  	"encodeURIComponent_not_encoded" : encodeURIComponent("-_.!~*'()"),
  	"encodeURI_not_encoded" : encodeURI("-_.!~*'()")
  }
}
```

#### Output

```JSON
{
  "comparing_encode_functions_output": {
    "encodeURIComponent": "%20PATH/%20TO%20/ENCODE%20",
    "encodeURI": "%20PATH/%20TO%20/ENCODE%20",
    "encodeURIComponent_to_hex": "%3B%2C%2F%3F%3A%40%26%3D",
    "encodeURI_not_to_hex": ";,/?:@&=",
    "encodeURIComponent_not_encoded": "-_.!~*'()",
    "encodeURI_not_encoded": "-_.!~*'()"
  }
}
```
