JSON to CSV API
Convert a JSON array of objects or arrays into CSV with a header row and a custom delimiter, returned as JSON or as a downloadable text/csv file.
Send a JSON array in json, either as a value or as a JSON string (a raw text/plain body also works). Each object becomes a row and its keys become the header; arrays of arrays are written as plain rows. Nested objects and arrays are serialized as JSON text inside the cell, and values with commas, quotes or line breaks are quoted correctly.
Columns are the union of the keys of all objects, in the order they first appear; missing values become empty cells. Use delimiter for a separator other than a comma (for example ; for European Excel) and header=false to omit the header row.
By default the response is JSON with csv and row_count; with format=csv the API answers with the raw CSV as text/csv, ready to save as a file. The request body is limited to 5 MB.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
json | body | array | yes | Array of objects or arrays, as a JSON value or JSON string. A raw text/plain body is also accepted. | |
delimiter | body|query | string | no | , | Field delimiter, e.g. ; or a tab. |
header | body|query | boolean | no | true | Write the header row with column names. |
format | body|query | string | no | json | Set to csv to receive the raw CSV (text/csv) instead of JSON. |
Example
curl -X POST "https://apibox.io.vn/v1/json-to-csv" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"json":[{"name":"Alice","age":30,"tags":["admin","dev"]},{"name":"Bob","age":25,"tags":[]}]}'const res = await fetch('https://apibox.io.vn/v1/json-to-csv', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"json": [
{
"name": "Alice",
"age": 30,
"tags": [
"admin",
"dev"
]
},
{
"name": "Bob",
"age": 25,
"tags": []
}
]
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/json-to-csv",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"json": [{"name": "Alice", "age": 30, "tags": ["admin", "dev"]}, {"name": "Bob", "age": 25, "tags": []}]},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/json-to-csv');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"json":[{"name":"Alice","age":30,"tags":["admin","dev"]},{"name":"Bob","age":25,"tags":[]}]}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"csv": "name,age,tags\nAlice,30,\"[\"\"admin\"\",\"\"dev\"\"]\"\nBob,25,[]",
"row_count": 2
}
Use cases
- Export API data or database query results to Excel or Google Sheets
- Generate downloadable CSV reports in a web app
- Convert JSON logs or analytics events into spreadsheets
- Prepare data for import tools that only accept CSV
FAQ
How are nested objects handled?
Nested objects and arrays are written as JSON text in the cell, for example ["admin","dev"].
Can I download the CSV file directly?
Yes. Add format=csv and the response body is the CSV itself with Content-Type: text/csv.
Which columns are included?
Every key found in any object of the array, in the order it first appears. Objects that lack a key get an empty cell.
Related APIs
JSON Validator
Check JSON syntax with exact line and column of errors, and validate data against a JSON Schema (draft 4, 7, 2019-09 or 2020-12).
{ }JSON Formatter
Pretty print JSON with 0-8 spaces or tabs, minify it, or sort object keys recursively. Syntax errors are reported with line and column.
CSVCSV to JSON
Convert CSV into an array of JSON objects using the header row, with delimiter auto-detection, number and boolean typing, and row-level errors.