parse_csv

Parses a CSV string into an array of objects. The first row is used as headers — each subsequent row becomes an object with header names as keys.

{% assign rows = file.content | parse_csv %}
{% for row in rows %}
  {% log row.sku | append: ": " | append: row.title %}
{% endfor %}

Syntax

{{ csv_string | parse_csv }}
Parameter
Description

csv_string

A string containing CSV-formatted data

Return Value

Returns an array of objects. Each object represents a row, with keys taken from the header row.

Examples

Parse a CSV file from file storage:

{% storage_read filename:"products.csv" as csv_content %}
{% assign rows = csv_content | parse_csv %}
{% log "Rows: " | append: rows.size %}
{% for row in rows %}
  {% log row %}
{% endfor %}

Parse an uploaded input file:

Parse CSV from an HTTP response:

Process CSV rows and update products:

Combine with left_join to match import data:

Notes

  • The first row is always treated as the header row

  • Auto-detects the delimiter (comma, semicolon, tab, etc.)

  • Returns an empty array if the input is empty or not a string

  • Throws an error on malformed CSV data

  • See also: parse_json, parse_xml

Last updated