How to use the Excel, CSV & JSON to JS Array
- Paste CSV, Excel cells or JSON, or open a file.
- Choose the shape: an array of objects, rows as arrays, or an object keyed by the first column.
- Pick the declaration (
const,export const,module.exports…), quote style and indentation. - Copy the code or download it as a
.jsfile.
What does a CSV to JavaScript array converter do?
It turns rows of a spreadsheet into a JavaScript literal you can drop into source code — handy for mock data, Storybook stories, unit tests, dropdown options, small lookup tables and static sites that do not need a database or a runtime CSV parser.
export const products = [
{ id: 1, name: 'Ada Lovelace', active: true },
{ id: 2, name: 'Grace Hopper', active: true },
];
JavaScript literal vs JSON
JSON is a strict subset of JavaScript syntax, but hand-written JavaScript is usually more relaxed. This tool writes idiomatic JavaScript:
- Unquoted keys when the key is a valid identifier (
name:), quoted only when needed ('first name':). - Single or double quotes to match your Prettier or ESLint settings.
- Trailing commas, which keep diffs to one line when you add rows.
- Real types: numbers, booleans and
nullare not quoted; values with leading zeros stay strings.
Shapes and declarations
| Option | Output |
|---|---|
| Objects | [{ id: 1, … }, …] — the usual array of records |
| Rows (lists) | [['id', 'name'], [1, 'Ada']] — header first, like a spreadsheet |
| Keyed by 1st column | { 'KB-001': { … } } — instant lookups by ID |
export const / export default | ES modules (Vite, Next.js, modern Node) |
module.exports | CommonJS (older Node.js code) |
With JSON input, Keep original JSON structure converts nested objects and arrays as they are. Need TypeScript types for the data? Generate them with JSON to TypeScript. For PHP projects use CSV to PHP array.
Tools that pair well with the Excel, CSV & JSON to JS Array
- Excel to JSON — Open an .xlsx workbook or paste cells straight from Excel or Google Sheets and get clean JSON.
- JSON to Excel — Turn a JSON array into a real Excel workbook.
- CSV & Excel to SQL — Paste CSV or Excel cells, or open an .xlsx file, and get ready-to-run CREATE TABLE and INSERT statements with correctly escaped values for your database.
- JSON to SQL — Paste a JSON array and get SQL that creates the table and inserts every object as a row — nested objects become columns or JSON values, and every string is escaped for your dialect.