CSV to JSON API

Turn CSV with a header row into an array of objects.

EndpointPOST https://astraljson.com/api/v1/csv-to-json
AuthBearer token, free
Sendsinput: text
Returnsresult: text
option2 | 4 | tab
PriceFree. 1,000 calls a day, 60 a minute.

When to call it

This is the import direction: a file a partner emails you, an export from a tool with no API, a sheet somebody maintains by hand. Parsing it in your own pipeline rather than by hand means the awkward rows, the ones with a comma inside a quoted field, are handled the same way every week.

For a one-off, the browser version needs no token and never sends your data anywhere: it runs on your own machine.

Example

curl
curl -X POST https://astraljson.com/api/v1/csv-to-json \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": "id,name,city\n1,\"Lovelace, Ada\",London\n2,Hopper,New York", "option": "2"}'
response
{
  "tool": "csv-to-json",
  "result": "[\n  {\n    \"id\": 1,\n    \"name\": \"Lovelace, Ada\",\n    \"city\": \"London\"\n  },\n  {\n    \"id\": 2,\n    \"name\": \"Hopper\",\n    \"city\": \"New York\"\n  }\n]",
  "chars": 141,
  "ms": 1
}

In your language

JavaScript
const res = await fetch("https://astraljson.com/api/v1/csv-to-json", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"input": "id,name,city\n1,\"Lovelace, Ada\",London\n2,Hopper,New York", "option": "2"}),
});
if (!res.ok) throw new Error((await res.json()).detail);
const { result } = await res.json();
Python
import os, requests

res = requests.post(
    "https://astraljson.com/api/v1/csv-to-json",
    headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
    json={"input": "id,name,city\n1,\"Lovelace, Ada\",London\n2,Hopper,New York", "option": "2"},
    timeout=30,
)
res.raise_for_status()
result = res.json()["result"]

Parameters

FieldTypeNotes
inputstringRequired. Up to 200,000 characters per call.
optionstringOne of: 2, 4, tab.

Errors

Errors are RFC 7807 problem documents with a stable type you can branch on.

missing-token401No Authorization header.
bad-request400input missing or the wrong type.
bad-option400option is not one of the listed values.
tool-failed422The input could not be processed. detail says why.
quota-exceeded429Past 1,000 calls today.

Questions

Does the first row have to be a header?
Yes. The header row names the keys of every object that comes back. A file without one will produce objects keyed by its first data row, which is almost never what you want.
Are numbers converted?
Yes, values that look like numbers or booleans come back as numbers and booleans rather than strings, which is what makes the output usable without a second pass.
What about quoted fields with commas or line breaks?
Handled. Quoted fields may contain commas, escaped quotes and newlines, and the parser keeps them inside the one value.

Other endpoints

A token takes thirty seconds

Free, no card, 1,000 calls a day, and the same token works on astraltext.com, astralpdf.com, astraljson.com and astralbatch.com.

Get a free token