Skip to main content

Base64Encode@1

Node Base64Encode@1 converts string values to Base64 encoded format. It encodes strings using UTF-8 character encoding and is essential for data serialization, secure transmission, and preparing data for APIs or storage systems that require Base64 format.

Adapter Prerequisites

  • General availability: All adapters support this node type.

Node Configuration

For fields path, targetPath, targetValueWriteMode, and targetValueKind, see Overview.

transformations:
- type: Base64Encode@1
path: $.users[*] # Path to objects containing string data
sourcePath: $.password # Path to string value to encode
targetPath: $.encodedPassword # Path where encoded value will be stored

Parameters

Required Parameters

ParameterTypeDescription
pathstringJSONPath to objects containing the string data to encode
sourcePathstringRelative path to the string value within each object
targetPathstringRelative path where the Base64 encoded value will be stored

Encoding Process

The node performs Base64 encoding through these steps:

  1. Object Selection: Uses path to select objects containing string data
  2. Value Retrieval: Extracts the string value from sourcePath
  3. UTF-8 Conversion: Converts the string to a UTF-8 byte array
  4. Base64 Encoding: Converts the byte array to a Base64 string
  5. Result Storage: Stores the encoded string at targetPath

Value Handling

  • Null Preservation: Null values are preserved without encoding
  • Type Conversion: Non-string values are converted to strings before encoding
  • Empty Strings: Empty strings are encoded (result in empty Base64 string)
  • UTF-8 Encoding: All strings are encoded using UTF-8 character set

Examples

Example 1: Encode User Passwords

Encode plaintext passwords to Base64 format:

transformations:
- type: Base64Encode@1
path: $.users[*]
sourcePath: $.password
targetPath: $.encodedPassword

Input:

{
"users": [
{ "id": "user1", "password": "password123" },
{ "id": "user2", "password": "mySecret456" }
]
}

Output:

{
"users": [
{ "id": "user1", "password": "password123", "encodedPassword": "cGFzc3dvcmQxMjM=" },
{ "id": "user2", "password": "mySecret456", "encodedPassword": "bXlTZWNyZXQ0NTY=" }
]
}

Example 2: Encode API Keys

Convert API keys to Base64 format for secure storage:

transformations:
- type: Base64Encode@1
path: $.services[*]
sourcePath: $.apiKey
targetPath: $.encodedApiKey

Input:

{
"services": [
{ "name": "API1", "apiKey": "secret-key-123" },
{ "name": "API2", "apiKey": "another-secret" }
]
}

Output:

{
"services": [
{ "name": "API1", "apiKey": "secret-key-123", "encodedApiKey": "c2VjcmV0LWtleS0xMjM=" },
{ "name": "API2", "apiKey": "another-secret", "encodedApiKey": "YW5vdGhlci1zZWNyZXQ=" }
]
}

Example 3: Encode Configuration Values

Encode sensitive configuration parameters:

transformations:
- type: Base64Encode@1
path: $.configuration.secure[*]
sourcePath: $.value
targetPath: $.encodedValue

Input:

{
"configuration": {
"secure": [
{ "key": "db_password", "value": "database_pass" },
{ "key": "api_token", "value": "token_123456" }
]
}
}

Output:

{
"configuration": {
"secure": [
{ "key": "db_password", "value": "database_pass", "encodedValue": "ZGF0YWJhc2VfcGFzcw==" },
{ "key": "api_token", "value": "token_123456", "encodedValue": "dG9rZW5fMTIzNDU2" }
]
}
}

Example 4: Encode File Content

Prepare text content for data URI or API transmission:

transformations:
- type: Base64Encode@1
path: $.files[*]
sourcePath: $.textContent
targetPath: $.base64Content

Input:

{
"files": [
{ "name": "readme.txt", "textContent": "Hello World!" },
{ "name": "config.json", "textContent": "{\"setting\": \"value\"}" }
]
}

Output:

{
"files": [
{ "name": "readme.txt", "textContent": "Hello World!", "base64Content": "SGVsbG8gV29ybGQh" },
{ "name": "config.json", "textContent": "{\"setting\": \"value\"}", "base64Content": "eyJzZXR0aW5nIjogInZhbHVlIn0=" }
]
}

Example 5: Handle Different Data Types

Encode various data types (automatically converted to strings):

transformations:
- type: Base64Encode@1
path: $.items[*]
sourcePath: $.data
targetPath: $.encodedData

Input:

{
"items": [
{ "id": 1, "data": "hello" },
{ "id": 2, "data": 12345 },
{ "id": 3, "data": true },
{ "id": 4, "data": null }
]
}

Output:

{
"items": [
{ "id": 1, "data": "hello", "encodedData": "aGVsbG8=" },
{ "id": 2, "data": 12345, "encodedData": "MTIzNDU=" },
{ "id": 3, "data": true, "encodedData": "VHJ1ZQ==" },
{ "id": 4, "data": null, "encodedData": null }
]
}

Example 6: Encode JSON Data

Encode structured data as Base64 strings:

transformations:
- type: Base64Encode@1
path: $.requests[*]
sourcePath: $.payload
targetPath: $.encodedPayload

Input:

{
"requests": [
{ "url": "/api/users", "payload": "{\"name\":\"John\",\"age\":30}" },
{ "url": "/api/orders", "payload": "{\"items\":[\"A\",\"B\"]}" }
]
}

Output:

{
"requests": [
{ "url": "/api/users", "payload": "{\"name\":\"John\",\"age\":30}", "encodedPayload": "eyJuYW1lIjoiSm9obiIsImFnZSI6MzB9" },
{ "url": "/api/orders", "payload": "{\"items\":[\"A\",\"B\"]}", "encodedPayload": "eyJpdGVtcyI6WyJBIiwiQiJdfQ==" }
]
}

Example 7: Encode for Email Headers

Prepare text for email header encoding:

transformations:
- type: Base64Encode@1
path: $.emails[*]
sourcePath: $.subject
targetPath: $.encodedSubject

Input:

{
"emails": [
{ "to": "user@example.com", "subject": "Héllo Wörld with Special Chärs" },
{ "to": "admin@example.com", "subject": "日本語のタイトル" }
]
}

Output:

{
"emails": [
{ "to": "user@example.com", "subject": "Héllo Wörld with Special Chärs", "encodedSubject": "SMOpbGxvIFfDtnJsZCB3aXRoIFNwZWNpYWwgQ2jDpHJz" },
{ "to": "admin@example.com", "subject": "日本語のタイトル", "encodedSubject": "65e5672c8a9e44gu44ov44kk44oi44or" }
]
}

Use Cases

  • Credential Storage: Encode sensitive data for configuration files (not for security)
  • API Transmission: Prepare binary data for JSON/XML APIs
  • Data URIs: Create data URIs for embedding content in web pages
  • File Upload: Encode file contents for API payloads
  • Email Headers: Encode non-ASCII characters in email headers
  • Configuration Obfuscation: Obfuscate configuration values (not for security)
  • Data Serialization: Prepare binary data for text-based protocols

Error Handling

The node will throw errors when:

  • The input data context is null
  • JSONPath expressions are invalid

Behavior Notes

  • UTF-8 Encoding: All strings are converted to UTF-8 bytes before Base64 encoding
  • Null Safety: Null values are preserved without causing errors
  • Type Conversion: Non-string values are converted using ToString() before encoding
  • Memory Efficient: Processing is done per object, not loading all data at once
  • Standard Encoding: Uses standard Base64 encoding (RFC 4648)

Security Considerations

  • Not Encryption: Base64 is encoding, not encryption - it provides no security
  • Obfuscation Only: Use only for data format compatibility, not for hiding sensitive data
  • Reversible: Base64 encoding is easily reversible and should not be relied upon for security
  • Proper Security: Use actual encryption methods for sensitive data protection

Performance Notes

  • Efficient Processing: Processes objects individually for better memory usage
  • String Conversion: Non-string values require string conversion before encoding
  • UTF-8 Overhead: UTF-8 encoding may increase byte count for some character sets
  • Base64 Expansion: Base64 encoding increases data size by approximately 33%