Skip to content

CSV Conversion

The /csv endpoint converts between CSV and JSON: parse turns CSV text into an array of objects, format does the reverse.

How it works?

The parser respects quoted fields, including escaped quotes ("") and newlines inside a quoted field. CRLF and CR line endings are normalized to LF before parsing.

Parameters

The request body must be JSON:

ParameterRequiredDescription
actionYesAction to perform: parse or format
csvCond.CSV text to convert (required for parse)
jsonCond.Array of objects to convert (required for format)
delimiterNoField separator, a single character. Default: ,
headersNoparse only: use the first row as object keys. Default: true

Available Actions

ActionDescription
parseConverts CSV text into an array of objects
formatConverts an array of objects into CSV text

Response Fields

parse action:

FieldTypeDescription
actionstringparse
rowsobject[]Array of parsed row objects
countnumberNumber of rows returned

format action:

FieldTypeDescription
actionstringformat
csvstringThe generated CSV text
countnumberNumber of rows converted

Code Examples

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "action": "parse",
    "csv": "name,age\nAlice,30"
  }' \
  "https://api.sylvain.sh/v5/csv"

Try It

Error Handling

If parameters are missing or invalid, the API will return an error:

Error MessageDescription
Please provide an action (?action=parse|format)The action parameter is missing
Please provide a valid action (?action=parse|format)The action value is not parse or format
Delimiter must be a single characterThe delimiter is not exactly one character
Please provide CSV data (?csv={data})The csv parameter is missing for parse
CSV cannot exceed 50000 charactersThe csv text exceeds the maximum length
CSV cannot exceed 1000 rowsThe parsed data has more rows than the limit
Please provide a JSON array (?json=[...])The json parameter is missing, not an array, or empty for format
JSON cannot exceed 1000 rowsThe json array has more rows than the limit