DataWeave 2.1 is compatible with Mule 4.1. Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule will reach its End of Life on November 2, 2022, when Extended Support ends.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

encodeURIComponent(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:

Type Includes

Reserved characters

Unescaped characters

alphabetic, decimal digits, - _ . ! ~ * ' ( )

Number sign


Name Description


URI component string.


This example encodes a variety of URI components.


%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("-_.!~*'()")


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

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Submit your feedback!
Share your thoughts to help us build the best documentation experience for you!
Take our latest survey!