JSON to CSV API

Turn an array of objects into RFC 4180 CSV, keys unioned across rows.

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

When to call it

The usual reason is that somebody downstream wants a spreadsheet: a finance team, a support export, a bulk upload form that only accepts CSV. Doing it in a scheduled job removes the step where a person pastes a payload into a converter, and it is the only way to make the conversion repeatable when the rows change shape between runs.

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/json-to-csv \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": "[{\"id\":1,\"name\":\"Ada, Lovelace\"},{\"id\":2,\"email\":\"g@example.com\"}]"}'
response
{
  "tool": "json-to-csv",
  "result": "id,name,email\r\n1,\"Ada, Lovelace\",\r\n2,,g@example.com",
  "chars": 51,
  "ms": 1
}

In your language

JavaScript
const res = await fetch("https://astraljson.com/api/v1/json-to-csv", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"input": "[{\"id\":1,\"name\":\"Ada, Lovelace\"},{\"id\":2,\"email\":\"g@example.com\"}]"}),
});
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/json-to-csv",
    headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
    json={"input": "[{\"id\":1,\"name\":\"Ada, Lovelace\"},{\"id\":2,\"email\":\"g@example.com\"}]"},
    timeout=30,
)
res.raise_for_status()
result = res.json()["result"]

Parameters

FieldTypeNotes
inputstringRequired. Up to 200,000 characters per call.

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.
tool-failed422The input could not be processed. detail says why.
quota-exceeded429Past 1,000 calls today.

Questions

What happens when the rows have different keys?
Every key seen in any row becomes a column, in the order it was first seen, and rows that lack it get an empty cell. Nothing is dropped.
Are commas and quotes inside values handled?
Yes, to RFC 4180: a field containing a comma, a quote or a newline is wrapped in quotes and its own quotes are doubled. Headers go through the same rule, which is a step the browser version used to skip.
What about nested objects?
A nested value is serialised as JSON inside its cell rather than being flattened or dropped, so the data survives the round trip even though a spreadsheet will show it as text.

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