Skip to main content

Encode / Decode

The Encode / Decode step converts one value from one coding into another: Base64, URL, XML, HTML and JSON escaping, Quoted-Printable, MIME header words (RFC 2047) and escaping for regular expressions. One value goes in, the converted value comes out as result.

Typical use cases:

  • Turn base64 content from an HTTP Request into readable text.
  • Build URL parameters with spaces, & or umlauts.
  • Put a value safely into XML, HTML or JSON text you build yourself.
  • Read the attachments of signed e-mails from Microsoft Graph together with the Parser step (see the example below).

Direction​

Encode converts plain text into the chosen format, Decode converts the format back into plain text.

Format​

FormatEncodeDecode
Base64Text as base64Base64 back to text. Spaces and line breaks are ignored.
Base64URLBase64 with - and _ instead of + and /, without = at the end – as used in web tokens and URLsThe same back to text
URL (form)Special characters as %XX, a space as + – for form data and query parameters%XX and + back to text
URL (path)Special characters as %XX, a space as %20 – for parts of a URL path%XX back to text, + stays
XML escape&, <, >, " and ' as &amp;, &lt;, …Entities such as &amp; or &#228; back to characters
HTML escapeLike XML escapeAdditionally named HTML entities such as &nbsp;, &auml; or &euro;
JSON escape", \, line breaks and tabs as \", \\, \n, \tBack to text, including ä
Quoted-PrintableSpecial characters as =XX, long lines wrapped – the coding of many e-mail textsBack to text
RFC 2047 (MIME header)Text with umlauts as =?utf-8?B?…?=, plain text unchangedEvery =?…?= word in the text back to text, e.g. file names of e-mail attachments
RegEx escapeCharacters with a special meaning in regular expressions (., +, ?, …) get a \– (only Encode)

Text is always read and written as UTF-8. RFC 2047 words name their own character set; UTF-8, ISO-8859-1, Windows-1252 and US-ASCII are supported.

Input​

The value to convert, usually the output of an earlier step, e.g. {{GetAttachments_contentBytes}}. An empty value gives an empty result.

If the input cannot be decoded – it is not valid base64, for example – the step stops the flow with an error.

Outputs​

OutputContent
resultThe converted value. Large values of several hundred kilobytes are no problem.

With debug logging switched on, the execution log shows the input and the result of the step.

Example: read attachments of signed e-mails (Microsoft Graph)​

When an e-mail is digitally signed (S/MIME), Microsoft Graph does not list its attachments one by one. Instead, the request /messages/{id}/attachments returns a single attachment smime.p7m with the content type multipart/signed. Its contentBytes hold the whole e-mail – text, attachments and signature – as base64. With Encode / Decode and the Parser you get the attachments out:

  1. HTTP Request to /messages/{id}/attachments, then a Parser (JsonPath) on $.value and a For Each over the attachments. A Decision checks whether the attachment is called smime.p7m.

  2. Encode / Decode – Direction Decode, Format Base64, Input {{Attachment_contentBytes}}. Slug Mime. {{Mime_result}} now holds the e-mail as text.

  3. Parser – type RegEx, Input {{Mime_result}}, one line part with the selector (?s)(Content-Type:(?:(?!\r\n\r\n).)*?Content-Disposition:\s*attachment.*?)(?=\r?\n--) It returns one value per attachment: part[0], part[1], …

  4. For Each over part, inside a Parser (RegEx) on the current part with these lines:

    LineSelector
    fileNamefilename\*?="?([^"\r\n;]+)
    contentTypeContent-Type:\s*([^;\r\n]+)
    encodingContent-Transfer-Encoding:\s*(\S+)
    body(?s)\r?\n\r?\n(.*)
  5. Encode / Decode – Direction Decode, Format RFC 2047 (MIME header) on fileName. This turns a name such as =?utf-8?B?UmVjaG51bmcgTcO8bGxlci5wZGY=?= into Rechnung Müller.pdf.

  6. Skip the part smime.p7s – that is the signature. For a PDF, body is already the file as base64 and can be passed on directly, e.g. as Base64 row of Create ZIP Archive. If encoding is quoted-printable, decode body with the format Quoted-Printable first.

If you need the boundary of the e-mail inside a regular expression, convert it with Direction Encode and Format RegEx escape first – boundaries often contain characters such as ., + or =.

Things to keep in mind​

  • Base64 → text is meant for text. Decoding a PDF or an image to text damages the content. Keep files as base64 and pass the base64 on.
  • Quoted-Printable is always read as UTF-8. E-mail texts in ISO-8859-1 show wrong umlauts after decoding.
  • The e-mail example covers the usual case. E-mails with unusual headers, forwarded e-mails attached as .eml and encrypted e-mails (application/pkcs7-mime) are not or only partly covered by the selectors.
  • JSON escape only escapes the content. Put the quotation marks around it yourself when you build JSON text.