base64_encode
Encodes a string to Base64 format. Useful for encoding data for APIs, creating basic authentication headers, or encoding binary data for transmission.
{% assign encoded = "Hello, World!" | base64_encode %}
{% log encoded %}
Output:
{{ string | base64_encode }}
Create Basic Authentication header:
{% assign credentials = "username:password" | base64_encode %}
{% assign auth_header = "Basic " | append: credentials %}
{% json http_options %}
{
"url": "https://api.example.com/data",
"method": "GET",
"headers": {
"Authorization": "{{ auth_header }}"
}
}
{% endjson %}
{% http options: http_options as response %}
Encode API credentials:
Encode JSON payload for URL parameter:
Encode data for webhook signature:
Create encoded return URL:
Encode file content reference:
Encode special characters for safe transmission:
Output:
Encode Unicode/international characters:
Output:
Common Use Cases
Encode JSON for query strings
Encode payload before signing
Hide readable values (not encryption!)
Supports UTF-8 encoding (handles international characters correctly)
Output is standard Base64 (uses +, /, and = padding)
For URL-safe Base64, you may need to replace characters: | replace: "+", "-" | replace: "/", "_"
Base64 encoding increases size by approximately 33%
This is encoding, not encryption - data can be easily decoded
See also: base64_decode for decoding Base64 strings