Parse fixed-width records into a table
The Fixed-Width File Parser turns column-positional flat files — the kind produced by mainframes, banks, and legacy systems — into clean CSV or JSON. You describe each field by its name, where it starts, and how many characters it spans, and the tool slices every line accordingly.
How it works
You provide a spec with one line per field in the form name,start,length, where
start is the 1-based character position of the field’s first column. The parser
validates that each line has three parts and that start and length are positive
integers, reporting a precise error if not.
For every input line, each field is extracted with a substring from start - 1
for length characters. Because JavaScript’s substring stops at the end of the
string, lines shorter than the full record width yield empty strings for the
trailing fields instead of failing. With trimming enabled, each extracted value
has its surrounding whitespace removed — important because fixed-width fields are
space-padded to fill their column. The records are then serialised either as a
JSON array of objects or as quoted CSV.
Example and notes
For the spec:
id,1,4
name,5,16
city,21,9
the line 0001JOHN SMITH LONDON parses to id=0001, name=JOHN SMITH,
city=LONDON. Keep id as a string here — leading zeros matter, and CSV/JSON
text output preserves them. If your file uses a header line with column names but
no explicit widths, measure the start columns of each header label to build the
spec.