Browse the docs

parseTable

Reads pasted CSV, TSV or spreadsheet cells into a list of records keyed by the header row.

Details #

parseTable(text, header?) reads rows and columns: comma, tab, semicolon or pipe separated, with quoted cells ("Smith, J") and embedded line breaks, the same reader Transform text uses for Paste As JSON. The first row names the columns, and every other row becomes a record keyed by them.

With header set to false you get a list of lists instead. Values stay text, so use parseNumber where you need a number.

Parameters #

Takes 1 to 2 arguments. {{ parseTable(text, b?) }}

Examples #

parseTable("name,age\nAda,36\nBob,41")
→ [ { "age" : "36", "name" : "Ada" }, { "age" : "41", "name" : "Bob" } ]
parseTable("name,age\nAda,36")[0].name
→ Ada
parseTable("1\t2\n3\t4", false)
→ [ [ "1", "2" ], [ "3", "4" ] ]

Gotchas #

  • It needs a header and at least one row (two lines), and every row must have the same number of cells. Otherwise it fails with parseTable() couldn't find a table.

  • A repeated header name gets _2, _3; an empty one is called column 3 (its position).