Turn a JSON array into a real XLSX file for the moment someone asks for the data and means a spreadsheet. The first object's keys set the column order, and keys that only appear in later rows become extra columns at the end. Numbers go into numeric cells, so formulas work on them. A nested object or array is written into its cell as JSON text, and an array of bare values gets a single value column.
[
{
"ID": 101,
"Name": "John Doe",
"Department": "Engineering",
"Salary": 85000,
"JoinDate": "2023-01-15"
},
{
"ID": 102,
"Name": "Jane Smith",
"Department": "Marketing",
"Salary": 72000,
"JoinDate": "2023-03-20"
},
{
"ID": 103,
"Name": "Bob Johnson",
"Department": "Sales",
"Salary": 90000,
"JoinDate": "2022-11-05"
}
] ID Name Department Salary JoinDate
101 John Doe Engineering 85000 2023-01-15
102 Jane Smith Marketing 72000 2023-03-20
103 Bob Johnson Sales 90000 2022-11-05 Finance, ops and management teams want a file they can sort and filter. An endpoint and an API token do not help them.
Use a pivot table for a one-off question. Load the download into Excel and a pivot table or chart usually answers it faster than a script would.
// npm install xlsx
const XLSX = require("xlsx");
const rows = [
{ id: 1, name: "Ada", joined: "2024-01-15", score: 98.5 },
{ id: 2, name: "Grace", joined: "2024-02-01", score: 91 },
];
const sheet = XLSX.utils.json_to_sheet(rows); // first object's keys = header row
const book = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(book, sheet, "Data");
XLSX.writeFile(book, "data.xlsx"); The same library runs in the browser, where XLSX.writeFile triggers a download instead of writing to disk.
# pip install openpyxl
import json
from openpyxl import Workbook
rows = json.loads('[{"id":1,"name":"Ada","score":98.5},{"id":2,"name":"Grace","score":91}]')
wb = Workbook()
ws = wb.active
ws.title = "Data"
headers = list(rows[0].keys())
ws.append(headers)
for row in rows:
ws.append([row.get(h) for h in headers]) # numbers stay numeric cells
wb.save("data.xlsx") If pandas is already in the project, pd.DataFrame(rows).to_excel("data.xlsx", index=False) does all of this in one line.
<?php
// composer require phpoffice/phpspreadsheet
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$rows = json_decode('[{"id":1,"name":"Ada","score":98.5},{"id":2,"name":"Grace","score":91}]', true);
$sheet = (new Spreadsheet())->getActiveSheet();
$sheet->fromArray(array_keys($rows[0]), null, 'A1'); // header row
$sheet->fromArray(array_map('array_values', $rows), null, 'A2');
(new Xlsx($sheet->getParent()))->save('data.xlsx'); fromArray() writes numbers as numeric cells and everything else as text.
An .xlsx file is a ZIP archive of XML parts, described by the Office Open XML standard (ECMA-376). Unlike CSV, it carries types: numbers, booleans, shared strings, and dates stored as serial day numbers with a number format. A string cell stays a string, so leading zeros, long IDs and Unicode text survive an .xlsx export where a CSV opened in Excel would mangle them.
Copy for Spreadsheet puts tab-separated text on the clipboard. Paste it into Excel or Google Sheets and it lands as a range of cells, which is quicker than saving and reopening a workbook for a small table.
This tool follows the specifications below. Read them when you need the exact normative wording, for example to settle an edge case between two implementations.
The keys of the first object set the column order, and keys that first appear in later objects are added as columns at the end. To change the order, reorder the keys in the first object before converting, or move the columns in Excel after downloading.
The output is a standard .xlsx (Office Open XML) workbook. Excel 2007 and later, Google Sheets, LibreOffice Calc and Apple Numbers all open it.
As JSON text in one cell. For example, an address object lands in the address column as {"city":"Oslo"}. The tool does not flatten nested fields into separate columns, so flatten the data first if you need to filter on them in Excel. A top-level array of bare values or arrays gets a single value column.
Numbers are written as numeric cells, so formulas work on them. JSON has no date type, so dates arrive as strings and are stored as text. Convert the column in Excel if you need date arithmetic.
Excel allows up to 1,048,576 rows per sheet. The tool builds the workbook in memory in your browser, so for very large arrays your device's memory is a limit too.
Use JSON to CSV when a plain text file is enough. To check the data before downloading anything, open it in the JSON table viewer.