← All procedures

csv.parse

Parse CSV text into rows

CLI
Package
@procedures/json · README
Path
["csv","parse"]
CLI
mark csv parse --text <string>
As data
{"$proc":["csv","parse"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/json/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["csv","parse"], { text: "<text>" });
console.log(JSON.stringify(result));

From the command line

$ mark csv parse --text <string>

As data, in a program

{ "$proc": ["csv", "parse"], "input": { "text": "<text>" } }

Input

FieldTypeRequiredDefaultDescription
textstringyesThe CSV text (RFC 4180)
headerbooleannoTrue: the first row has the names of the columns, and each other row is an object
delimiterstringnoThe character between two fields (default: a comma)
trimbooleannoTrue: remove the white space at the start and at the end of each field
skipEmptyLinesbooleannoFalse: an empty line gives a row with one empty field (default: true, skip each empty line)
quotestringnoThe character around a field that has the delimiter, a line break or a quote (default: a double quote)

Output

FieldTypeRequiredDefaultDescription
rowsany[]yesThe rows, in the order of the text
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string",
        "description": "The CSV text (RFC 4180)"
      },
      "header": {
        "description": "True: the first row has the names of the columns, and each other row is an object",
        "type": "boolean"
      },
      "delimiter": {
        "description": "The character between two fields (default: a comma)",
        "type": "string",
        "minLength": 1,
        "maxLength": 1
      },
      "trim": {
        "description": "True: remove the white space at the start and at the end of each field",
        "type": "boolean"
      },
      "skipEmptyLines": {
        "description": "False: an empty line gives a row with one empty field (default: true, skip each empty line)",
        "type": "boolean"
      },
      "quote": {
        "description": "The character around a field that has the delimiter, a line break or a quote (default: a double quote)",
        "type": "string",
        "minLength": 1,
        "maxLength": 1
      }
    },
    "required": [
      "text"
    ]
  },
  "output": {
    "type": "object",
    "properties": {
      "rows": {
        "type": "array",
        "items": {
          "description": "A row: an array of fields, or with header an object of fields by column name"
        },
        "description": "The rows, in the order of the text"
      }
    },
    "required": [
      "rows"
    ],
    "additionalProperties": false
  }
}