Back to Blog
Developer Tools

CSV to JSON โ€” Import Spreadsheet Data Into APIs and Applications

2026-06-03 4 min read

Convert CSV files to JSON arrays for API consumption. Auto-detects numbers, supports custom delimiters, runs entirely in your browser.

You got a CSV file. Your API expects JSON. This is such a common workflow that it's worth understanding how the conversion works, not just which button to click. CSV parsing has edge cases that trip up simple implementations.

The basic structure

A CSV file has a header row with column names, followed by data rows. Each value in a row corresponds to the column at that position. The converter maps each row to a JSON object using the headers as keys:

// Input CSV
id,name,email,active
1,Alice,alice@example.com,true
2,Bob,bob@example.com,false

// Output JSON
[
  { "id": "1", "name": "Alice", "email": "alice@example.com", "active": "true" },
  { "id": "2", "name": "Bob", "email": "bob@example.com", "active": "false" }
]

Type inference

Notice that everything comes out as a string. A good converter infers types: if a value is 1, output the number 1. If it's true, output the boolean. If it's empty, output null. You might want to disable type inference and keep everything as strings if your API expects strings.

CSV edge cases to handle

// Values with commas must be quoted
1,"Smith, John",john@example.com

// Values with quotes: the quote is doubled
2,"Alice ""Al"" Jones",alice@example.com

// Values with newlines inside quotes
3,"Line 1
Line 2",email@example.com

// Empty values
4,,email@example.com

Parsing in Node.js

The csv-parse library handles all edge cases correctly:

import { parse } from "csv-parse/sync";
import { readFileSync } from "fs";

const csv = readFileSync("data.csv", "utf-8");
const records = parse(csv, {
  columns: true,    // use first row as headers
  skip_empty_lines: true,
  cast: true,       // auto-convert types
});

console.log(records);
// [{ id: 1, name: "Alice", email: "alice@example.com", active: true }]

Different delimiters

Not all "CSV" files use commas. TSV (tab-separated) is common from spreadsheet exports. European locales often use semicolons because commas are used as decimal separators. Always check the delimiter before parsing.

Convert CSV to JSON in one click with our CSV to JSON tool.

csv json convert import api data

More Articles