Back to Blog
Developer Tools

Convert API JSON Response to Excel โ€” JSON to CSV to XLSX Workflow

2026-06-03 4 min read

API JSON data can flow to Excel in two steps: convert to CSV, then open in Excel. Here is the complete workflow with no upload required.

Product managers, finance teams, and clients all want Excel. Your data lives in an API. The path from JSON API response to .xlsx file is a few steps, and there's a clean way to do each one.

Step 1: Fetch the API data

const response = await fetch("https://api.example.com/reports/sales", {
  headers: { Authorization: "Bearer YOUR_TOKEN" },
});
const data = await response.json();
// [{ date: "2026-06-01", product: "Widget A", sales: 150, revenue: 4500 }, ...]

Step 2: Convert to CSV (simple path)

For basic tables, CSV is enough and Excel opens it perfectly:

function downloadAsCsv(data, filename) {
  const headers = Object.keys(data[0]);
  const rows = data.map(row =>
    headers.map(h => JSON.stringify(row[h] ?? "")).join(",")
  );
  const csv = [headers.join(","), ...rows].join("
");

  const blob = new Blob([csv], { type: "text/csv" });
  const url = URL.createObjectURL(blob);
  const a = document.createElement("a");
  a.href = url;
  a.download = filename;
  a.click();
  URL.revokeObjectURL(url);
}

Step 3: Proper Excel files with SheetJS

If you need actual .xlsx with formatting, multiple sheets, or formulas, use SheetJS (also called xlsx):

import * as XLSX from "xlsx";

function downloadAsExcel(data, filename = "export.xlsx") {
  // Create workbook and worksheet
  const wb = XLSX.utils.book_new();
  const ws = XLSX.utils.json_to_sheet(data);

  // Optional: set column widths
  ws["!cols"] = [
    { width: 12 }, // date column
    { width: 20 }, // product column
    { width: 10 }, // sales column
    { width: 12 }, // revenue column
  ];

  XLSX.utils.book_append_sheet(wb, ws, "Sales Report");
  XLSX.writeFile(wb, filename);
}

Adding multiple sheets

// Multiple sheets from different API endpoints
const [sales, expenses] = await Promise.all([
  fetch("/api/sales").then(r => r.json()),
  fetch("/api/expenses").then(r => r.json()),
]);

const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, XLSX.utils.json_to_sheet(sales), "Sales");
XLSX.utils.book_append_sheet(wb, XLSX.utils.json_to_sheet(expenses), "Expenses");
XLSX.writeFile(wb, "financial-report.xlsx");

For a quick one-off conversion without writing code, use our JSON to CSV tool and open the result in Excel.

api json excel csv convert data

More Articles