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

# 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": "-_.!~*'()"
  }
}
```
