translate

This page explains how to use the translate function in APL.

Use the translate function in APL (Axiom Processing Language) to substitute characters in a string, one by one, based on their position in two input lists. For every character in the input string that matches a character in the first list, translate replaces it with the character at the same position in the second list.

This function is useful when you want to:

  • Replace specific characters without using complex regular expressions.
  • Normalize text by mapping characters to a consistent format.
  • Obfuscate or scrub data by transforming characters to placeholders.

Usage

Syntax

translate(searchList, replacementList, source)

Parameters

NameTypeDescription
searchListstringCharacters to search for in the input string.
replacementListstringCharacters to replace each match in searchList.
sourcestringThe input string to evaluate.

Returns

A string with characters from searchList replaced by corresponding characters in replacementList. If replacementList is shorter than searchList, Axiom repeatedly uses the last character of replacementList to match the length of the search.

Use case examples

Use translate to mask user IDs by replacing all lowercase letters with asterisks.

Query

['sample-http-logs']
| extend masked_id = translate('0123456789abcdefghijklmnopqrstuvwxyz', '##########*', id)
| project _time, id, masked_id

Run in Playground

Output

_timeidmasked_id
2025-07-28T12:34:56Zbd6d8f17-2b8d-4b71-af20-f23dc8d20202**#*#*##-#*#*-#*##-**##-*##**#*#####
2025-07-28T12:35:01Z1e317368-9ed4-4e8c-b535-b59a68ffda05#*######-#**#-#*#*-*###-*##*##****##

This query masks characters in the id field by replacing numbers with hashes and letters with asterisks.

Use translate to remove vowels from service names for compact representation.

Query

['otel-demo-traces']
| extend compact_service = translate('aeiou', '', ['service.name'])
| project _time, ['service.name'], compact_service

Run in Playground

Output

_timeservice.namecompact_service
2025-07-28T10:00:00Zproduct-catalogprdct-ctlg
2025-07-28T10:01:00Zfrontendfrntnd

This example reduces the length of the service.name field by eliminating vowels.

Use translate to standardize HTTP status codes by masking digits with a symbol.

Query

['sample-http-logs']
| extend normalized_status = translate('0123456789', '#', status)
| project _time, status, normalized_status

Run in Playground

Output

_timestatusnormalized_status
2025-07-28T13:45:00Z200###
2025-07-28T13:45:05Z404###

This use case replaces all digits in HTTP status codes with # characters, helping anonymize numeric values.

Other query languages