tobase64()
Converts a binary value to a Base64-encoded string and returns it.
Syntax
tobase64(BLOB_EXPR)
Parameters
BLOB_EXPR- The binary value or expression to encode as Base64.
Description
The tobase64() function encodes binary (byte[]) as Base64 and returns it as a string. If the argument is null, returns null. If a non-binary value is passed, returns null. If an array or list is passed, encoding is applied recursively to each element.
Error codes
N/A
Usage examples
-
Converting a string to binary and then Base64 encoding it
json "{'val': 'hello, world!'}" | eval result = tobase64(binary(val)) | # result: "aGVsbG8sIHdvcmxkIQ==" -
Non-binary value input
json "{'val': 1234}" | eval result = tobase64(val) | # result: null -
NULL input
json "{'val': null}" | eval result = tobase64(val) | # result: null
Compatibility
The tobase64() function has been available since before Sonar 4.0.