- 2 minutes to read

Formula - base64decode

The base64decode Formula function decodes base64 text and returns the original text, read with UTF-8 or with the source encoding you name.

Syntax

base64decode(content [, 'source encoding'])

Parameters

Parameter Required Description
content Yes The base64 text to decode: body, context, or the result of another function, such as jsonPath.
'source encoding' No The character encoding of the decoded bytes, such as 'UTF-8' or 'iso-8859-1'. Use the encoding the sender used before it encoded the text. Without it, the bytes are read as UTF-8.

Returns

The decoded text. When the content holds several values, for example from jsonPath, each value is decoded and returned as its own Search Field value. When the content has no value, nothing is returned.

Examples

Example 1: Decode a base64 message body

Input

bm9kaW5pdGU=

Formula

base64decode(body)

Result

nodinite

Test Expression tab: base64decode(body) decodes the message body bm9kaW5pdGU= to nodinite
The base64 body decodes to nodinite with the default UTF-8 encoding.

Example 2: Decode UTF-8 text with a special character

Input

U2tlbGxlZnRlw6U=

Formula

base64decode(body, 'UTF-8')

Result

Skellefteå

Test Expression tab: base64decode(body, 'UTF-8') decodes U2tlbGxlZnRlw6U= to Skellefteå
The two UTF-8 bytes for å decode correctly because the source encoding matches.

Example 3: Decode ISO-8859-1 text

The same word, encoded from ISO-8859-1 bytes, is a different base64 string. Name the encoding to read the bytes correctly.

Input

U2tlbGxlZnRl5Q==

Formula

base64decode(body, 'iso-8859-1')

Result

Skellefteå

Test Expression tab: base64decode(body, 'iso-8859-1') decodes U2tlbGxlZnRl5Q== to Skellefteå
In ISO-8859-1, å is the single byte E5, so the base64 text differs from Example 2 but decodes to the same word.

Example 4: Decode a context property

Input

Key Value
id bm9kaW5pdGU=

Formula

base64decode(context('id'))

Result

nodinite

Test Expression tab: base64decode(context('id')) decodes the context value bm9kaW5pdGU= to nodinite
The value of the context property id is decoded; the message body isn't used.

Example 5: Decode several values from a JSON body

Input

[ { "name": "YXdlc29tZQ==" }, { "name": "ZnVuY3Rpb24=" } ]

Formula

base64decode(jsonPath('$..name',body))

Result

awesome
function

Test Expression tab: base64decode of a jsonPath result returns two decoded values, awesome and function
jsonPath returns two base64 values, and base64decode decodes each one: two unique matches.

Notes

  • The source encoding must match the bytes inside the base64 text. Reading ISO-8859-1 bytes as UTF-8 turns characters such as å into replacement characters.
  • When every message of a Message Type is logged as base64, you can set its encoding to a Base64 Decode into … option instead. The Logging Service then decodes the body before any Search Field Expression runs, so plain body is already text; see Base64 Decode into an encoding.
  • Encoding names follow .NET; see the List of encodings.

Next Steps