TextManipulation icon

TextManipulation

Allows you to manipulate string values.

Overview

The TextManipulation node is designed to perform advanced text manipulation tasks within n8n workflows. It allows users to extract text from various sources (plain text, files, or JSON fields), apply a wide range of manipulations (such as case conversion, encoding/decoding, concatenation, replacement, trimming, padding, substring extraction, and repetition), and then output the manipulated result either as JSON data or as a binary file.

Common scenarios:

  • Cleaning and formatting text data before sending it to another system.
  • Converting file encodings or extracting specific content from uploaded files.
  • Replacing sensitive information or unwanted patterns in text.
  • Preparing text for further processing, such as converting to uppercase, normalizing, or extracting substrings.

Practical examples:

  • Reading a CSV file, removing all HTML tags, and saving the cleaned text as a new file.
  • Extracting a string from a JSON field, converting it to snake_case, and updating the original JSON.
  • Decoding a base64-encoded string from a file, replacing certain words, and writing the result back to a binary property.

Properties

1. Keep Only Set (boolean)

  • Display Name: Keep Only Set
  • Type: Boolean
  • Description: If enabled, only the values set on this node will be kept; all other properties will be removed from the output.

2. Texts with Manipulations (fixedCollection)

  • Display Name: Texts with Manipulations
  • Type: Collection (multiple, sortable)
  • Description: Defines one or more text manipulation pipelines. Each pipeline consists of:
    • Data Sources: Where to read the text from.

      • Read Operation: Choose between "Text" (direct input), "Read From File", or "Read From JSON".
        • For "Read From File":
          • Binary Property: Name of the binary property to read.
          • Decode With: Encoding to use when reading.
          • Strip BOM: Whether to remove Byte Order Mark.
          • Get Manipulated Data: Use manipulated data if available.
        • For "Read From JSON":
          • Source Key: JSON key (supports dot notation).
          • Skip Non-String: Skip non-string data or convert to string.
          • Get Manipulated Data: Use manipulated data if available.
        • For "Text":
          • Text: Direct plain text input.
    • Write Operation: Where to write the manipulated result.

      • Write to File: Output as binary data.
        • Destination Binary Property: Name for the output binary property.
        • Encode With: Encoding for output.
        • Add BOM: Add Byte Order Mark.
        • File Name: Name for the output file.
        • Mime Type: MIME type for the output file.
      • Write to JSON: Output as JSON data.
        • Destination Key: JSON key to store the result (supports dot notation).
    • Manipulations: List of manipulations to apply, in order. Each manipulation can be:

      • Concat: Add strings before/after.
      • Decode/Encode: Change encoding.
      • Decode/Encode Entities: Handle HTML/XML entities.
      • Letter Case: Convert to upper/lower/camel/snake/kebab/title case, etc.
      • Normalize: Unicode normalization forms.
      • Pad: Pad at start/end to a target length.
      • Repeat: Repeat the string N times.
      • Replace: Replace substrings, regex matches, or predefined character groups/tags.
      • Substring: Extract a substring by position or length.
      • Trim: Remove characters from start/end/both sides.
    • Each manipulation has its own set of options, such as which encoding to use, what pattern to replace, how to trim, etc.


Output

Structure

  • json: The main output object, containing the manipulated data. If "Write to JSON" is selected, the manipulated text is stored under the specified key (dot notation supported).
  • binary: If "Write to File" is selected, the manipulated text is encoded and attached as a binary property with the specified name, file name, and MIME type.

Example Output (JSON):

{
  "json": {
    "data": "manipulated text here"
  }
}

Example Output (Binary):

{
  "json": {},
  "binary": {
    "data": {
      "data": "<base64-encoded-manipulated-content>",
      "fileName": "example.txt",
      "mimeType": "text/plain"
    }
  }
}
  • If "Keep Only Set" is enabled, only the properties explicitly set in the node will appear in the output.

Dependencies

  • External Libraries:

    • iconv-lite: For encoding/decoding text in various formats.
    • entities: For handling HTML/XML entity encoding/decoding.
    • lodash: For utility functions (case conversion, deep get/set, etc.).
    • string-strip-html (dynamically imported): For removing HTML tags when using the "tags" predefined rule in replacements.
  • n8n Requirements:

    • No special API keys or environment variables are required.
    • The node expects valid binary data if reading/writing files.

Troubleshooting

Common Issues

  • Missing Binary Property:
    If the specified binary property does not exist in the input, the node will skip processing that item.
  • Invalid Encoding:
    If an unsupported encoding is selected, the node may throw an error.
  • Incorrect JSON Key:
    If the source or destination key does not exist or is misspelled, the node may not find or store the data as expected.
  • Non-String Data:
    If "Skip Non-String" is enabled and the data is not a string, it will be skipped. Otherwise, it will be converted to a string.
  • Invalid Manipulation Options:
    Providing invalid options (e.g., negative lengths, missing required fields) will cause the node to throw descriptive errors.

Error Messages

  • "fromFile, fromJSON or fromText are valid options":
    Triggered if an invalid read operation is specified.
  • "toFile or toJSON are valid options":
    Triggered if an invalid write operation is specified.
  • "upperCase, lowerCase, capitalize, camelCase, kebabCase or snakeCase are valid options":
    Triggered if an invalid case type is provided.
  • "The Target Length has to be set to at least 0 or higher!":
    Occurs if a negative value is given for padding length.
  • "The Times has to be set to at least 0 or higher!":
    Occurs if a negative repeat count is provided.
  • "tags or characterGroups are valid options":
    Occurs if an invalid predefined rule is used in replacement.
  • "complete, position or length are valid options":
    Occurs if an invalid end option is used for substring extraction.

Resolution:
Check your node configuration for typos, ensure all required fields are filled, and verify that the data types match expectations.


Links and References


Discussion