Actions9
Replace Keywords
AI-generatedOverview
This node performs various utility text and data transformations, including replacing keywords in a template text with values from a JSON object. Specifically, the 'Replace Keywords' operation takes a template string containing placeholders (e.g., {{key}}) and replaces these placeholders with corresponding values provided in a JSON replacements string. This is useful for dynamically generating personalized messages, notifications, or documents by substituting placeholders with actual data.
Use Case Examples
- Generating personalized order confirmation messages by replacing placeholders like {{name}} and {{order_id}} with customer-specific values.
- Creating customized email templates where keywords are replaced with user data from a JSON object.
Properties
| Name | Meaning |
|---|---|
| Template Text | The text containing placeholders (keywords) in the format {{key}} that need to be replaced. |
| Replacements (JSON) | A JSON string containing key-value pairs where keys correspond to placeholders in the template text and values are the replacement strings. |
Output
JSON
success- Indicates if the operation was successful.operation- The operation performed, here it is 'replaceKeywords'.original_text- The original template text before replacements.result_text- The resulting text after all replacements have been made.replacements- The parsed JSON object containing the replacement key-value pairs.replacement_count- The total number of replacements made in the template text.replaced_keys- An array of keys that were replaced in the template text.
Troubleshooting
- Ensure the 'Template Text' input is not empty; otherwise, the node will throw an error indicating the template text is required.
- The 'Replacements (JSON)' input must be valid JSON; invalid JSON will cause a parsing error and the node will throw an error indicating invalid JSON in the replacements field.
- Placeholders in the template text must exactly match keys in the replacements JSON enclosed in double curly braces (e.g., {{key}}). Mismatched keys will not be replaced.