Loading

Why DataWeave percent-encodes "~" (tilde) when writing application/x-www-form-urlencoded

Publiseringsdato: Oct 20, 2026
Oppgave

Why is "~" in the payload percent-encoded as "%7E" when the DataWeave output is application/x-www-form-urlencoded?

Trinn

ANSWER

The DataWeave urlencoded writer (UrlEncodedWriter) encodes each key and value with java.net.URLEncoder. URLEncoder implements the HTML form-encoding rules: it leaves only letters, digits and "* - . _" unencoded, writes a space as "+", and percent-encodes everything else, including "~". For example:
a~b c  ->  a%7Eb+c

This matches the application/x-www-form-urlencoded format defined by the HTML/WHATWG URL standard, which also encodes "~". RFC 3986 section 2.3 lists "~" as unreserved, but RFC 3986 defines generic URI syntax, not form bodies. The difference between URLEncoder and RFC 3986 is tracked by the OpenJDK issue JDK-8204530 (open); DataWeave follows the JDK behaviour.

The encoding does not change the data. Any compliant form decoder converts "%7E" back to "~", and RFC 3986 section 2.3 also states that URIs differing only in the percent-encoding of an unreserved character are equivalent.

If a receiving system rejects "%7E", that system is not decoding form data correctly. Raise it with the owner of that system first. As a last resort, the encoded string can be post-processed, for example:
write(payload, "application/x-www-form-urlencoded") replace "%7E" with "~"
This is a custom workaround, not a product feature. Test it against the receiving system.

Knowledge-artikkelnummer

001114352

 
Laster
Salesforce Help | Article