CSV to Array of Arrays (No Headers)
Convert CSV data into a JSON array of arrays instead of objects. Ideal for headerless CSV files, matrix data, and compact JSON output.
Advanced Conversion
Detailed Explanation
CSV to Array of Arrays
Not every CSV-to-JSON conversion needs named keys. Sometimes the most appropriate output is a simple array of arrays, where each inner array represents one row of values.
Input CSV
2024-01,150,89.5
2024-02,203,92.1
2024-03,178,87.3
Output JSON
[
["2024-01", "150", "89.5"],
["2024-02", "203", "92.1"],
["2024-03", "178", "87.3"]
]
When to use array-of-arrays format
- Headerless CSV data. Sensor readings, log entries, and matrix data often lack a header row. Forcing artificial key names adds no value.
- Compact output. By omitting repeated key names, the JSON output can be 30-50% smaller. For a CSV with 10 columns and 1,000 rows, that eliminates 10,000 repeated key strings.
- Grid/table rendering. Frontend table components often accept
[headers[], ...rows[][]]format directly. - Data pipelines. When the consumer already knows the schema, named keys are unnecessary overhead.
Implementation
function csvToArrays(csv) {
return csv
.trim()
.split("\n")
.map(line => line.split(",").map(cell => cell.trim()));
}
With optional header separation
If the CSV does have headers but you want arrays:
{
"headers": ["month", "sales", "satisfaction"],
"rows": [
["2024-01", "150", "89.5"],
["2024-02", "203", "92.1"]
]
}
This hybrid format gives you the compactness of arrays with the self-documenting benefit of header names. It is commonly used by charting libraries and spreadsheet APIs.
Caveats
- Column order matters. Unlike objects, arrays are positional, so reordering columns changes the meaning.
- Missing values must be represented by empty strings or null placeholders to maintain alignment.
- Consumers must reference values by index (
row[0]) rather than by name (row.month), which is less readable.
Use Case
Feeding time-series CSV data from IoT sensors into a charting library like Chart.js that expects data as arrays of [label, value] pairs rather than named objects.