Hands typing on a laptop displaying a data spreadsheet

Photo by Gorilla ROI Data Connector on Unsplash

Somebody emails you a spreadsheet. Or you export one yourself, a customer list or an order history, and the next thing that needs it is an API that only speaks JSON. You open the CSV in a text editor and it looks simple. Commas, rows, done. Then you paste it into the first converter you find and your ZIP codes come out wrong.

That last part is the whole story. Here's how to convert CSV to JSON without breaking your data: paste the CSV into a converter that runs in your browser, check the first row is your headers, and copy the JSON out. If you convert the same export every week, write the five-line Python script instead. Either way, watch the trap: CSV stores every value as text, so a tool that guesses types will turn the ZIP code 02134 into 2134.

What the conversion actually does

A CSV file is a table with no memory. It doesn't know that 02134 is a ZIP code and not a number, or that "Smith, John" is one name and not two fields. JSON is the format that remembers: each row becomes one object, and the header row becomes the keys.

Take this export:

name,zip,orders
"Smith, John",02134,7
Ana,90210,3

Converted, with every value kept as text, it becomes:

[
  {"name": "Smith, John", "zip": "02134", "orders": "7"},
  {"name": "Ana", "zip": "90210", "orders": "3"}
]

Two things in that example are doing quiet work. The quotes around "Smith, John" keep the comma inside the name from splitting it into two fields, and 02134 stays a string, leading zero intact. Lose either and the JSON is valid but the data is wrong.

How to convert CSV to JSON online

The fastest way, for a file you'll convert once, is the free CSV to JSON Converter. Nothing's uploaded: the whole job runs on your own machine, which matters when the spreadsheet holds real people's details.

  1. Pick the direction at the top: CSV to JSON, or JSON to CSV.
  2. Paste your data into the box, drop a file onto it, or open one up to 20 MB. Try the sample first if you want to see the shape of the output. The first row has to be your column headers. Those become the JSON keys.
  3. The output appears as you type, with a count of the rows converted. If a row has more fields than the header, the tool warns you instead of silently dropping data. Choose pretty, minified or JSON Lines output, and whether numbers and true/false become real values.
  4. Copy the result, or download it as a .json, .jsonl or .csv file.
  5. If your CSV has no header row, add one first. Without it you get generic keys like column1, which no API will know what to do with.

By default every value stays a string, exactly as it appeared in the CSV. That's what protects phone numbers, ZIP codes and IDs with leading zeros. Tick "Numbers and true/false as values" and 7 becomes a number and true becomes a boolean, but 02134 still stays text. That default is right for most files, so turn the toggle on only when you know every column is safe to type.

The trap that ruins conversions

CSV records no types. Every cell is text until something decides otherwise, and the something that decides is usually wrong in exactly the cases that matter. A ZIP code loses its zero. A product code like 1e5 becomes 100000. Excel is the worst offender: open a CSV in it and it'll reformat dates and large numbers before you've even saved anything, and the damage is in the file by the time you convert it.

So the rule is simple: treat every column as a string unless you've explicitly decided otherwise, for that column, in that file. The browser tool does this by default. Python's standard library does it too. Pandas doesn't, which is why the pandas section below comes with a warning attached. And if the output looks wrong, the input is almost always the culprit: open the CSV in a plain text editor, not in Excel, to see what's actually there. Usually it's a quote that never got closed.

How to convert CSV to JSON with Python

If the same export lands in your inbox every week, write the script once. The standard library is enough, and it needs nothing installed:

import csv
import json

with open('customers.csv', newline='', encoding='utf-8-sig') as f:
    rows = list(csv.DictReader(f))

with open('customers.json', 'w', encoding='utf-8') as f:
    json.dump(rows, f, indent=2)

DictReader uses the first row as field names and hands you one dictionary per row, and every value stays a string. The utf-8-sig encoding handles files saved with a byte-order mark, which is how Excel writes CSVs on Windows. For a semicolon-separated file, add delimiter=';' to the DictReader call.

Pandas does the same job in two lines, for files already in a data workflow. But it infers types aggressively and treats NA, N/A and null as missing values by default, so guard the columns that must stay text:

import pandas as pd

df = pd.read_csv('customers.csv', dtype={'zip': str}, keep_default_na=False)
df.to_json('customers.json', orient='records', indent=2, force_ascii=False, date_format='iso')

The dtype argument keeps the ZIP column as text, and date_format='iso' matters because to_json writes dates as epoch milliseconds by default. In Node.js, the csv-parse package is the equivalent tool.

Which method wins

For a one-off file, the browser tool wins. Ten seconds, no setup, and it protects the columns you forgot about. For a file that arrives on a schedule, the Python script wins, because hand-pasting the same export every week is how mistakes creep in. Pandas wins only when the data's already in a DataFrame, and it's the easiest to get subtly wrong, so use it with the dtype guard above or not at all.

What the browser tool can't do

Files over 20 MB don't belong in a browser tab. Split them, or use the Python script, which reads a row at a time. A CSV with no header row gives you generic keys. Add the headers first. An unclosed quote is reported as an error, and the fix is in the CSV, not the tool. Going the other way, JSON to CSV writes nested objects as JSON inside a single cell.

Before you paste the result anywhere, run it through the JSON Formatter. A green Valid JSON bar tells you the syntax is sound. If you've got two versions of the same export, compare them first with the CSV & Excel Diff tool. And if the export is full of repeated rows, our guide to removing duplicate lines cleans them up before the conversion.

Quick answers

Will my ZIP codes survive the conversion?
Yes, if the tool keeps values as text. The browser converter does that by default, and so does Python's csv module. The danger is a tool that guesses types: 02134 becomes 2134, and there's no way to get the zero back.

What if my CSV has no header row?
Add one. Open the file, type the column names as the first line, save it, then convert. Without headers the converter invents generic keys like column1, and whatever consumes the JSON won't know which field is which.

What is JSON Lines?
One JSON object per line, with no array wrapped around them. Log tools, BigQuery and a lot of data pipelines read and write it, because they can process one line at a time. Pick it when the destination asks for .jsonl files.

Can I convert JSON back to CSV?
Yes. The same tool works both ways: pick JSON to CSV at the top, or open a .json or .jsonl file and it switches for you. The columns become every key found in any object, in the order they first appear. Nested objects come out as JSON inside a single cell.

Is my data uploaded anywhere?
No. The conversion happens in your browser, so customer lists and order exports stay on your device. That's the reason to use an in-browser converter for a spreadsheet with real people's details in it.

Keep the original CSV. Convert a copy and check the output before you paste it into the API. The mistake that costs people is converting their only copy and deleting the spreadsheet. The CSV is the source of truth. The JSON is a copy you can always make again.