StructuredFile/Parse Task
Overview
The StructuredFile/Parse@1 task converts position-based fixed-width flat files into structured JSON format. This task is essential for processing legacy file formats commonly used in warehouse management systems, transportation, and EDI integrations.
Task Definition
task: "StructuredFile/Parse@1"
name: parseStructuredFile
inputs:
fileData: "AASNTBCHUSPSWAREHOUSE123 SHR123456 MBL1234567890..."
config: { ... } # Detailed configuration object
parseMode: "structured" # Optional: "flat" or "structured" (default: "flat")
encoding: "UTF-8" # Optional: Character encoding (default: "UTF-8")
skipEmptyLines: true # Optional: Skip empty lines (default: true)
trimFields: true # Optional: Trim whitespace from fields (default: true)
outputs:
- name: "parsedData"
mapping: "result"
- name: "recordCount"
mapping: "recordCount"
- name: "recordTypes"
mapping: "recordTypes"
- name: "parseErrors"
mapping: "errors"
Input Parameters
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
fileData | string | Yes | - | Raw flat file content to parse |
config | object | Yes | - | Configuration defining file structure and parsing rules |
parseMode | string | No | "flat" | Output format: "flat" returns array of records, "structured" returns hierarchical object |
encoding | string | No | "UTF-8" | Character encoding of the input file |
skipEmptyLines | boolean | No | true | Whether to skip empty lines during parsing |
trimFields | boolean | No | true | Whether to trim whitespace from extracted field values |
Configuration Object
The configuration object is the core of the parser, defining how to interpret the flat file structure.
Basic Structure
config:
# Define output structure (for structured mode)
structured: true
structure: [...]
# Define record formats
records: [...]
# Global options
options:
includeFillers: false
includeRecordType: true
dateFormat: "YYYYMMDD"
Records Configuration
Each record type in the flat file must be defined in the records
array:
records:
- id: "A" # Single character that identifies this record type
name: "header" # Logical name for the record type
description: "File header record" # Optional description
required: true # Whether this record must appear in valid files
minOccurrences: 1 # Minimum times this record must appear
maxOccurrences: 1 # Maximum times this record can appear
fields: [...] # Field definitions for this record
Field Configuration
Each field within a record is defined with precise positioning and optional transformations:
fields:
- name: "carrier_code" # Field name in output
description: "SCAC code" # Optional field description
start: 9 # Starting position (1-based)
length: 4 # Number of characters
type: "string" # Data type (see Field Types section)
required: true # Whether field must have a value
trim: true # Override global trim setting
padCharacter: " " # Character used for padding
padDirection: "left" # Padding direction: "left" or "right"
defaultValue: "" # Default if field is empty
skip: false # Whether to exclude from output
validation: # Optional validation rules
pattern: "^[A-Z]{4}$"
minLength: 4
maxLength: 4
Field Types
The parser supports several field types with automatic conversion:
String (default)
- name: "description"
start: 10
length: 30
type: "string"
transform: "uppercase" # Optional: "uppercase", "lowercase", "capitalize"
Number
- name: "quantity"
start: 40
length: 6
type: "number"
divisor: 100 # Divide extracted value by this amount
decimals: 2 # Number of decimal places
thousandSeparator: "," # Optional thousand separator
defaultValue: 0
Date
- name: "ship_date"
start: 10
length: 8
type: "date"
inputFormat: "YYYYMMDD" # Format in the file
outputFormat: "YYYY-MM-DD" # Desired output format
timezone: "UTC" # Optional timezone
Boolean
- name: "is_hazmat"
start: 50
length: 1
type: "boolean"
trueValues: ["Y", "1", "T"] # Values that represent true
falseValues: ["N", "0", "F"] # Values that represent false
defaultValue: false