Skip to content
Log in

csv - Liquid Filter Reference

On this page

Description

Serializes a map or list as CSV. It is the CSV counterpart of json, designed for feed templates.

  • A map becomes one row of the map’s values, in key order, with no header.
  • A list of maps becomes a header row (the first map’s keys) followed by one row per map.
  • A list of plain values becomes one comma-separated row.

Each cell is escaped the same way as csv_escape, and rows are separated by a line feed. A cell that holds a list or map has no CSV form, so build a flat map before you serialize it.

In a CSV feed, the output is marked as already encoded, so the feed does not escape it a second time.

Property Value
Return Type string
Category collections

Examples

```liquid

{%- new Map row -%} {%- assign row = row | set_key: “sku”, “FR-3000” | set_key: “name”, “Fridgetastic 3000, white” -%} {{ row | csv }} ```

Output: FR-3000,"Fridgetastic 3000, white"

Collect rows in a list to emit a whole CSV document with a header row:

```liquid

{%- new List rows -%} {%- for record in record_set.records -%} {%- new Map row -%} {%- assign row = row | set_key: “code”, record.productcode | set_key: “name”, record.name -%} {%- assign rows = rows | push: row -%} {%- endfor -%} {{ rows | csv }} ```

Output: a header row code,name, then one row per record.

Was this article helpful?

Was this article helpful?