CSV to JSON

Convert a CSV string to a JSON array of objects with headers as keys.

Code

Utilities
const [header, ...rows] = csv.split('\n').map(row => row.split(','));
return rows.map(row => Object.fromEntries(header.map((h, i) => [h, row[i]])));

Parameters

CSV string to convert.

Browser·fetch() may be limited by CORS

More JavaScript Snippets