DEV Community

Pirate Prentice
Pirate Prentice

Posted on

n8n Convert to File Node: Build CSV, JSON, Excel, XML, and Text Files from Workflow Data [Free Workflow JSON]

If you need to turn n8n items into a downloadable file — a CSV report, a JSON export, an Excel workbook, or an XML feed — the Convert to File node is the right tool. This guide covers every supported output format, the configuration options that matter, common gotchas, and three copy-paste workflow patterns with free JSON.


What the Convert to File Node Does

The Convert to File node takes n8n items (JSON objects) and serializes them into a binary file that subsequent nodes can email, upload to S3/Drive/FTP, or return as an HTTP response.

It is the inverse of the Extract From File node: Extract reads files into items; Convert writes items into files.


Supported Output Formats

Format Output
CSV Comma-separated; one row per item
JSON Array of objects or single object
HTML Simple table representation
XML Nested XML from JSON structure
Text One line per item field or custom template
XLS Legacy Excel 97-2003 format
XLSX Modern Excel (default for spreadsheets)
ODS OpenDocument Spreadsheet (LibreOffice)

Node Configuration

Operation — select your target format. Each format exposes its own options.

Put Output File in Field — the binary property name on the output item (default: data). Downstream nodes (Email, S3, HTTP Response) reference this name.

CSV options

  • File Name — set a filename including extension (e.g., report.csv). Defaults to file.csv.
  • Header Row — toggle off to omit headers if the consumer doesn't expect them
  • Include BOM — adds UTF-8 BOM () for Excel compatibility on Windows (prevents garbled characters in the first column)
  • Delimiter — default comma; set to \t for TSV

JSON options

  • FormatEach Item Separately outputs one JSON file per item; All Items wraps all items in an array
  • File Name — e.g., export.json

XML options

  • Root Element — wraps the output in a named XML root tag (e.g., records<records>...</records>)
  • Attribute Prefix — keys prefixed with @ in JSON become XML attributes (default @)
  • Item Element — the XML tag wrapping each item (default: item)

XLSX / XLS / ODS options

  • Sheet Name — name the worksheet (default: Sheet1)
  • File Name — e.g., monthly-report.xlsx

Common Gotchas

1. Output lands in data but the next node expects a different property name
The node sets the binary property to data by default. If your Email node is configured to attach attachment, update Put Output File in Field to attachment — or use a Move Binary Data node to rename it.

2. Nested objects flatten unexpectedly in CSV
CSV is inherently flat. If your items contain nested objects ({"address": {"city": "Austin"}}), the CSV will render [object Object]. Flatten with a Set node first:

={{ $json.address.city }}
Enter fullscreen mode Exit fullscreen mode

3. Numbers become strings in CSV
All CSV values are strings. Downstream consumers (Excel, Google Sheets) may need explicit type casting on import. If precision matters, use XLSX instead.

4. XML with arrays requires careful structuring
If an item field is an array, the XML output can produce unexpected nesting. Test with a sample item before sending to production.

5. Large datasets and memory
Convert to File loads all input items into memory before writing. For datasets > 10,000 rows, use Split in Batches upstream to write in chunks and concatenate downstream — or write directly to disk with Read/Write Files node.

6. File name must include the extension
report without .csv will confuse email clients and browsers. Always set report.csv, export.xlsx, etc.


Three Workflow Patterns

Pattern 1: Weekly CSV Report via Email

Trigger: Schedule (every Monday 08:00)
Google Sheets / Postgres: Pull last week's records
Convert to File: Format = CSV, File Name = weekly-report.csv, Include BOM = on (Excel compatibility)
Gmail: Send email with CSV as attachment — set attachment binary field to match Put Output File in Field

This replaces a manual export-and-email cycle. Every Monday the report lands in the right inbox automatically.

{
  "name": "Weekly CSV Email Report",
  "nodes": [
    {"type": "n8n-nodes-base.scheduleTrigger", "name": "Monday 8am", "parameters": {"rule": {"interval": [{"field": "weeks"}]}}},
    {"type": "n8n-nodes-base.googleSheets", "name": "Get Last Week Data", "parameters": {"operation": "getAll", "sheetId": "YOUR_SHEET_ID"}},
    {"type": "n8n-nodes-base.convertToFile", "name": "Build CSV", "parameters": {"operation": "csv", "options": {"fileName": "weekly-report.csv", "includeBOM": true}}},
    {"type": "n8n-nodes-base.gmail", "name": "Email Report", "parameters": {"operation": "send", "subject": "Weekly Report", "attachmentsUi": {"attachmentsBinary": [{"property": "data"}]}}}
  ]
}
Enter fullscreen mode Exit fullscreen mode

Pattern 2: JSON Export Endpoint

Trigger: Webhook (GET /export)
Postgres / MySQL: Query all active records
Convert to File: Format = JSON, Format = All Items, File Name = export.json
Respond to Webhook: Return the file as a binary response with Content-Type: application/json

Useful for giving downstream systems a pull-based export endpoint without standing up a dedicated API.


Pattern 3: XLSX Report to Google Drive

Trigger: Schedule (end of month)
HTTP Request: Fetch data from internal API
Set: Map and clean fields (flatten nested objects)
Convert to File: Format = XLSX, Sheet Name = Summary, File Name = monthly-summary.xlsx
Google Drive: Upload to a shared reports folder

Finance and ops teams get a formatted Excel workbook in Drive without any manual intervention.


Free Workflow JSON

Download a ready-to-import workflow covering all three patterns above:

👉 n8n Workflow Starter Pack — pirateprentice.gumroad.com/l/sxcoe

Import via n8n → Settings → Import Workflow. Credentials not included — wire your own after import.


Related Articles


What files are you generating with n8n — CSV reports, Excel exports, JSON feeds? Drop a comment below with your use case.

Top comments (0)