NNonkera
Developer ToolsUpdated July 31, 2026

How to Convert a CSV File to JSON (and Back)

How CSV and JSON map to each other, why quoted fields matter, and what to watch for when converting nested JSON data back down to flat CSV rows.

How the two formats map to each other

CSV is fundamentally flat and tabular — rows and columns, with the first row conventionally holding column headers. JSON, by contrast, naturally represents structured objects. Converting CSV to JSON turns each data row into one object, using the header row's values as that object's keys, so a CSV with columns name,role becomes an array of {"name": ..., "role": ...} objects. Converting JSON back to CSV reverses this: it flattens each object into a row, using the combined set of keys found across all the objects as the column headers.

Why naive comma-splitting breaks

The simplest possible CSV parser — split every line on commas — fails the moment a field itself contains a comma, which is common in real data (an address like "123 Main St, Apt 4", or free-text notes). The CSV standard handles this with quoting: a field containing a comma, quote, or line break gets wrapped in double quotes, and a literal double quote inside a quoted field is escaped by doubling it (""). A parser that doesn't account for this quoting will silently shift every column after the broken field over by one — a subtle, easy-to-miss corruption rather than an obvious error.

What happens to nested data going the other way

JSON can represent nested objects and arrays as a value inside another object — something CSV has no native way to express, since CSV is strictly two-dimensional. When converting JSON to CSV, a nested object or array value typically gets converted to its literal string form rather than expanded into its own columns. If your JSON has meaningful nested structure, it's worth deliberately flattening it first — deciding which nested fields deserve their own column — rather than relying on the raw stringified output, which is rarely what you actually want to end up in a spreadsheet.

Common situations where this conversion comes up

Pulling a spreadsheet export into a script or API that expects JSON is one of the most frequent reasons to convert CSV to JSON, since JSON is the native format for most modern web tooling while CSV remains the default export format for spreadsheets and many databases. The reverse — JSON to CSV — comes up when handing data to someone who works in Excel or Google Sheets rather than code, or when a system specifically requires a CSV file for import.

Frequently asked questions

Does CSV-to-JSON conversion require a header row?

Yes — the standard approach uses the first row as the object keys for every subsequent data row.

What happens to commas inside a CSV field?

As long as the field is properly quoted (wrapped in double quotes), a comma inside it is preserved correctly rather than being mistaken for a column separator.

Can CSV represent nested JSON data?

No — CSV is strictly flat and two-dimensional, so nested objects or arrays in JSON get converted to a literal string when flattened to CSV, rather than expanded into their own columns.

What if my JSON objects don't all have the same keys?

A proper converter uses the union of all keys found across every object as the CSV columns, leaving a blank cell for any object that's missing a given key.

Is my data uploaded anywhere during conversion?

Not with a browser-based converter — the conversion runs locally in JavaScript, with nothing sent to a server.