Actions2
Overview
The Fixed-Width File node for n8n enables you to read data from or write data to files formatted with fixed-width fields. In the "Read From File" operation, it parses a binary file (such as .txt or .dat) where each field has a specific width, extracting structured data from each line according to your field definitions.
Common scenarios:
- Importing legacy data from mainframe or COBOL systems that use fixed-width text files.
- Processing bank statements, payrolls, or other standardized reports delivered in fixed-width format.
- Integrating with partners who provide or require data in fixed-width files.
Practical example:
You receive a batch of customer records in a fixed-width file, where each line contains a name (20 characters), age (3 characters), and balance (10 characters). This node can parse each line into a JSON object for further processing in your workflow.
Properties
| Name | Type | Meaning |
|---|---|---|
| Binary Property | String | Name of the binary property from which to read the fixed-width formatted file's binary data. |
| Fields | Fixed Collection | Defines the structure of each record. Each field specifies: - Property Name: Where to store the value (supports dot notation). - Type: Data type (Boolean, Float, Integer, Number, String). - Width: Number of characters for this field. (Align is not used in "Read From File") |
| Options → End-of-Line Character | String | The character(s) that separate rows/records in the file (default: \n). |
| Options → Trim | Options | How to trim whitespace/padding from parsed values. Choices: Both, None, Left, Right. Default: Both. |
| Options → Relaxed Parsing | Boolean | If true, partial/incomplete lines are parsed without error. Default: false. |
Output
Each output item represents a parsed record from the file:
{
"json": {
// Parsed fields as defined in "Fields"
"property1": "value1",
"property2": 123,
...
},
"pairedItem": <index>
}
- The
jsonobject contains key-value pairs as specified by your "Fields" configuration. - If an error occurs and "Continue On Fail" is enabled, the output may include an
errorfield describing the issue.
Binary output:
This operation does not produce binary output; it only reads/parses binary input.
Dependencies
- External library:
@evologi/fixed-widthfor parsing fixed-width files. - No external API keys or services required.
- No special n8n environment variables needed.
Troubleshooting
Common issues:
- Incorrect field widths: If the sum of field widths does not match the actual line length, parsing errors or misaligned data may occur.
- Missing binary data: If the specified binary property does not exist on the input item, that item will be skipped.
- Partial lines: By default, incomplete lines cause errors unless "Relaxed Parsing" is enabled.
- Encoding mismatches: If the file uses an unexpected encoding, parsing may fail or produce garbled results.
Error messages:
"Cannot read properties of undefined (reading 'binary')": The input item lacks the expected binary property. Check your input and the "Binary Property" setting."Invalid field definition": Your "Fields" configuration may be missing required attributes like width or property name."Line too short"or similar: The file contains lines shorter than the total field width. Enable "Relaxed Parsing" if this is acceptable.