Guide

CSV to JSON: A Complete Guide for Developers and Analysts

CSV and JSON are the two formats you meet most often when moving data between spreadsheets, databases, APIs and apps. CSV is flat and compact — ideal for tables. JSON is structured and self-describing — ideal for code and APIs. Converting between them sounds trivial, but a handful of details (quotes, delimiters, data types, nesting) decide whether the result works.

What each format looks like

CSV (comma-separated values):

name,plan,seats
Acme Corp,Pro,25
Globex,Starter,5

The same data as a JSON array of objects:

[
  {"name": "Acme Corp", "plan": "Pro", "seats": "25"},
  {"name": "Globex", "plan": "Starter", "seats": "5"}
]

The header row of the CSV becomes the keys; each data row becomes one object. You can do this conversion in your browser with the CSV to JSON converter.

When to use which

Use CSV when… Use JSON when…
Data is a simple table Data has nested structure (an order with line items)
People will open it in Excel or Google Sheets An API, web app or config file will read it
File size matters for large exports Field names should travel with the data
Importing into a CRM, email tool or database You need explicit types (numbers, booleans, null)

The five details that break conversions

1. Commas inside values

A value like Austin, TX contains the delimiter. Proper CSV wraps such values in double quotes: "Austin, TX". Simple converters that split on every comma will break the row into extra columns. If your tool does not parse quotes, export with a different delimiter (tab or pipe) instead.

2. The delimiter itself

Spreadsheet software in many European locales exports CSV with semicolons, because the comma is used as a decimal separator. Check the first line of the file and set the delimiter to match.

3. Data types

CSV has no types — everything is text. A converter has to decide whether 25 becomes the number 25 or the string “25”. Keeping strings is safer: ZIP codes like 02134, product codes and phone numbers lose leading zeros if converted to numbers. Convert types deliberately in your code where needed.

4. Encoding

Names with accents or non-Latin scripts turn into garbled characters when a file is saved in one encoding and read in another. Save CSVs as UTF-8 whenever you have the choice.

5. Empty values and headers

Decide whether empty cells should become empty strings or null. Make sure header names are unique and contain no stray spaces — duplicate headers overwrite each other as JSON keys.

A clean conversion workflow

  1. Tidy the sheet first. One header row, no merged cells, no notes below the table. Our data cleaning checklist covers this in detail.
  2. Export as CSV (UTF-8). Or copy the cells and use the Excel to CSV converter.
  3. Check the delimiter by opening the file in a text editor.
  4. Convert to JSON.
  5. Validate the result in the JSON formatter, and spot-check a few records against the original.
  6. Convert types in your application code where numbers or booleans are required.

Going the other way: JSON to CSV

Flat JSON arrays convert neatly to CSV. Nested JSON needs a decision: flatten nested fields into columns (address.city), create one row per nested item (one row per order line), or keep the nested part as a JSON string in a single column. Choose based on how the CSV will be used.

Handling large files

Browser tools are convenient for files up to a few megabytes. For larger exports, use a script — for example Python’s built-in csv and json modules or the pandas library — which also gives you full control over quoting, types and encoding.

Key takeaways