How to Convert CSV to JSON (Online, Python, and Excel)

The fastest way to learn how to convert CSV to JSON is to paste your CSV into a free online converter and copy out the JSON it produces. Each row of the spreadsheet becomes one JSON object, the header row becomes the keys, and the whole table becomes an array of objects. It takes about 30 seconds, and you do not need to write any code.

That is the short answer, and for a one-off conversion it is the whole answer. But if you convert CSV files regularly — feeding data into an API or an app — it pays to know the code routes too, and to know the traps that turn good data into wrong data.

Close-up of colorful CSS code lines on a computer screen

CSV to JSON in 30 Seconds (Online Converter)

Open Toollan’s free CSV to JSON Converter, paste your CSV (or upload the file), and copy the JSON output. The converter reads the first row as the headers, turns each following row into an object with those headers as keys, and wraps the objects in an array.

Give it this CSV:

name,role,age,city
Maya,designer,29,Leeds
Liam,developer,34,Manchester
Sofia,manager,41,Bristol

And you get this JSON back:

[
  {
    "name": "Maya",
    "role": "designer",
    "age": "29",
    "city": "Leeds"
  },
  {
    "name": "Liam",
    "role": "developer",
    "age": "34",
    "city": "Manchester"
  },
  {
    "name": "Sofia",
    "role": "manager",
    "age": "41",
    "city": "Bristol"
  }
]

Notice that the ages come out as strings ("29") rather than numbers (29). That is not a bug — CSV has no type system, so every value starts life as text. Whether that matters depends on what you do with the JSON next, and the traps section below explains when to convert the types and when to leave them alone.

Once you have the JSON, paste it into the free JSON Formatter to check it is valid and to make it readable.

How the Conversion Works: Rows Become Objects

The mapping between CSV and JSON is simple, and understanding it makes every method below easier to follow.

  • The header row becomes the keys. The first line of the CSV (name,role,age,city) gives the key names for every object. If your CSV has no header row, the converter has to invent keys — usually column1, column2, and so on — which is rarely what you want. Add a header row first if it is missing.
  • Each data row becomes one object. The values in a row pair up with the headers, in order, to make one JSON object per row.
  • The whole table becomes an array. The objects go into a JSON array, in the same order as the rows in the CSV.
  • Every value is a string to start with. CSV does not record types, so a converter that guesses types can get them wrong. A converter that keeps everything as a string is the safe default; you convert the columns you know are numeric afterwards.

There is one shape decision to make: an array of objects (shown above) is the standard output and what most APIs expect. The alternative is JSON Lines, where each row is one JSON object on its own line, with no wrapping array. JSON Lines is useful for streaming tools and log processing, but it is not a single JSON document — you cannot paste it into a JSON validator and get a pass. Pick the array unless you have a specific reason to want lines.

How to Convert CSV to JSON in Python (csv + json)

Python’s standard library does this with no packages to install. csv.DictReader reads each row as a dictionary keyed by the headers, and json.dump writes the list of dictionaries to a file. Here is the complete script, tested and working:

import csv
import json

with open("team.csv", newline="", encoding="utf-8") as csv_file:
    rows = list(csv.DictReader(csv_file))

with open("team.json", "w", encoding="utf-8") as json_file:
    json.dump(rows, json_file, indent=2, ensure_ascii=False)

Three details matter. First, open the CSV with newline="" — this lets the csv module handle line endings inside quoted fields itself. Second, pass indent=2 to json.dump so the output is readable rather than one long line. Third, ensure_ascii=False keeps international characters and emoji as themselves instead of escaping them to codes like \u00e9.

If the CSV came from Excel, open it with encoding="utf-8-sig" instead of "utf-8". Excel sometimes saves CSV files with a byte order mark (BOM) at the start, and without the -sig variant the BOM attaches itself to the first header name, so your first key becomes something odd instead of name and nothing matches it later.

To convert the types on the columns you know are numeric, cast them as you read:

for row in rows:
    row["age"] = int(row["age"])

Do this only for columns you have checked — a blank cell or a dash in the column will crash the script with a ValueError.

If you already use pandas, the same job is two lines: df = pd.read_csv("team.csv") followed by df.to_json("team.json", orient="records", indent=2). Pandas guesses the types for you, which is convenient and also the source of the leading-zero trap in the last section — read that before you trust the output.

Convert CSV to JSON in JavaScript / Node.js

JavaScript has no built-in CSV parser, so the reliable route is a small library. csv-parse is the standard choice: it handles quoted fields, commas inside fields, and line breaks inside quoted values, all of which break a hand-written split(","). Install it with npm install csv-parse, then:

import { readFileSync, writeFileSync } from "node:fs";
import { parse } from "csv-parse/sync";

const csvText = readFileSync("team.csv", "utf-8");
const records = parse(csvText, { columns: true, skip_empty_lines: true });
writeFileSync("team.json", JSON.stringify(records, null, 2));

The columns: true option tells the parser to use the first row as keys, and skip_empty_lines: true drops the blank lines that often sit at the end of a CSV file. JSON.stringify(records, null, 2) writes the output with two-space indentation, matching the Python example above. Run on the same sample file, this produces exactly the same JSON as the Python script.

Do not be tempted to parse CSV with line.split(","). It works on tidy sample data and fails on real data the first time a field contains a comma inside quotes — an address like "12 High Street, Leeds" splits into two fields and shifts every column after it. Use a real parser.

Close-up view of colorful code on a laptop screen

From Excel or Google Sheets to JSON

Neither Excel nor Google Sheets has a built-in “Save as JSON” option, so the route from a spreadsheet to JSON goes through CSV:

  1. In Excel, choose File > Save As and pick CSV UTF-8 (Comma delimited). In Google Sheets, choose File > Download > Comma Separated Values (.csv).
  2. Convert the CSV file to JSON with the online converter, the Python script above, or the Node script above.
  3. Check the result in the JSON Formatter to confirm it is valid.

Pick the UTF-8 CSV option in Excel, not the plain “CSV” one. The plain option uses your system’s local encoding, which mangles accented characters and non-Latin text. The UTF-8 option keeps them intact.

A few spreadsheet-specific things to check before you export. Merged cells do not survive a CSV export — only the top-left cell keeps its value, and the rest export as blanks. Formulas export as their calculated values, not as the formulas, which is usually what you want. And numbers formatted with thousand separators (1,000) export with the comma still in them, which then needs quoting in the CSV; it is cleaner to remove the thousand separators before you export. For more on getting the most out of Google’s apps, see our Google Workspace tips for beginners.

The Traps: Types, Leading Zeros, Quotes, and Commas Inside Fields

CSV to JSON is easy to do and easy to do slightly wrong. These are the traps, in the order you are most likely to meet them.

Leading zeros disappear. This is the classic. A US zip code of 02134, a product code of 007, or a phone number starting with 0 will lose the zero the moment a tool decides the value is a number. 02134 becomes 2134, and the data is wrong in a way that is hard to spot afterwards. The rule: treat every column as a string unless you have explicitly decided it is numeric. The Python csv module and the online converter both keep everything as strings by default, which is the safe starting point.

Automatic type guessing goes wrong. Tools that guess types can turn the product code 1e5 into the number 100000, turn a date into a different date, or turn a long ID number into scientific notation. If your converter has a “detect types” option, leave it off unless you have checked every column.

Commas inside fields. A field that contains a comma must be wrapped in double quotes in the CSV: "12 High Street, Leeds". A proper parser handles this; a naive split on commas does not. If your JSON output has values in the wrong columns, a quoted comma is the first thing to check.

Quotes inside fields. A double quote inside a field is written as two double quotes in CSV: "She said ""hello""". Again, a real parser handles it, and a hand-rolled one usually does not.

Dates are strings too. 2026-03-04 might be 4 March or 3 April depending on who wrote the file. JSON has no date type, so the value stays a string and the meaning depends on your code. Agree on the ISO format (year-month-day) before the data moves anywhere.

Empty cells. An empty cell becomes an empty string ("") in the JSON, not a null. If your API expects null for missing values, convert the empty strings after parsing rather than hoping the converter guesses.

The habit that avoids all of these: convert with types off, open the JSON, and eyeball the first few objects before you use the file. It takes ten seconds and catches every trap on this list.

Top-down view of a laptop keyboard and colorful printed charts on a desk

Frequently Asked Questions

How do I convert CSV to JSON online?

Paste your CSV into a free CSV to JSON converter and copy the JSON output. The first row becomes the keys, each following row becomes one object, and the objects are wrapped in an array. Check the result in a JSON formatter to confirm it is valid.

How to convert CSV to JSON in Python?

Use the standard library: csv.DictReader reads each row as a dictionary keyed by the headers, and json.dump writes the list to a file. Open the CSV with newline=”” and encoding=”utf-8″ (or “utf-8-sig” for files saved by Excel), and pass indent=2 to json.dump for readable output.

Why do my numbers come out as strings in the JSON?

Because CSV has no type system, so every value is text. Converters that keep everything as strings are doing the safe thing: a zip code of 02134 stays “02134” instead of becoming 2134. Convert only the columns you know are numeric, after the conversion.

Can Excel export directly to JSON?

No, Excel has no built-in JSON export. Save the sheet as CSV UTF-8 first (File > Save As > CSV UTF-8), then convert the CSV to JSON with an online converter or a short Python script. Google Sheets works the same way: File > Download > Comma Separated Values.

Close-up of a person using a laptop with spreadsheets and text on the screen

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top