A product list lives in a spreadsheet, and the new website wants it as JSON. A partner sends a CSV export that needs to be loaded into an API. A test suite needs fixtures, and it is far easier to maintain them as a sheet than as hand-written JSON. In each case you need to turn rows and columns into an array of objects, and do it without mangling the data.
It sounds like a job for a one-line script that splits on commas. This guide explains why that approach fails on real files, how a proper CSV parser works, the choices you make about headers and data types, and how to do the conversion in a browser, a spreadsheet or code.
Why splitting on commas is not enough
CSV looks simple, but real exports use a few rules (formalised in RFC 4180) that break naive parsing:
order_id,customer,amount,notes
1001,"Sharma, Rohan",1499.50,Deliver after 6 pm
1002,Meera Iyer,899,"She said ""call first"""
1003,Kabir Singh,2350,"Gift wrap
Two items in one box"
- Quoted fields can contain the delimiter.
"Sharma, Rohan"is one field, not two. - Quotes inside quoted fields are doubled.
""call first""means the text contains"call first". - Quoted fields can contain line breaks. Order 1003 spans two physical lines but is one record.
line.split(",") gets all three wrong: it splits the customer name, leaves stray quotes, and treats the second line of the note as a new record. A real parser reads character by character and tracks whether it is inside quotes.
There are also regional differences. Spreadsheets in countries that use a comma as the decimal separator usually export CSV with semicolons, and many systems export tab-separated files. A good converter detects the delimiter or lets you choose it.
Headers, keys and data types
Converting also involves decisions that the CSV file itself does not answer.
Headers. If the first row holds column names, each data row becomes an object keyed by those names: {"order_id": 1001, "customer": "Sharma, Rohan", ...}. If there is no header row, each row becomes a plain array of values.
Types. CSV has no types; every cell is text. JSON distinguishes strings, numbers, booleans and null. Converting 1499.50 to the number 1499.5 is usually what you want for amounts. Converting a ZIP code 02134 to the number 2134 is never what you want.
Messy headers. Real sheets have blank header cells and duplicated names like two columns called Phone. The converter needs a rule for both, or keys will overwrite each other.
Convert CSV to JSON with our tool
The CSV to JSON Converter uses a quote-aware parser and runs in your browser, so the file stays on your device.
- Open the CSV to JSON Converter. Paste the data into CSV input, or use Open file for a
.csv,.tsvor.txtfile up to 20 MB. Load sample shows a file with quoted commas, doubled quotes and a multi-line note. - Leave Delimiter on Auto-detect, or pick Comma, Semicolon, Tab or Pipe. When auto-detecting, the tool shows which delimiter it chose.
- Keep First row is header on to get objects, or turn it off to get arrays.
- Keep Typed values on to turn numbers into JSON numbers and
true,falseandnullinto their JSON equivalents. Turn it off to keep every value as a string. - Choose the JSON indent (2 spaces, 4 spaces or Tab), then Copy or Download the result.
A few rules are worth knowing. Values with leading zeros such as 00450 or 02134 stay strings even when typing is on, and so do integers too large for JavaScript to hold exactly, so codes and long IDs survive. Blank header cells become column1, column2 and so on, and a repeated header gets a suffix (Phone, Phone_2). If a row is shorter than the header, the missing fields are null. A byte order mark at the start of the file is ignored. If a quoted field is never closed, the tool tells you which line the quote started on.
Other ways to do it
From Excel or Google Sheets
Neither spreadsheet has a native "save as JSON" option. Save or download the sheet as CSV (File → Save As → CSV UTF-8 in Excel, File → Download → Comma-separated values in Google Sheets), then convert the CSV. Choose the UTF-8 option in Excel so accented names survive.
Python
import csv, json
with open("orders.csv", newline="", encoding="utf-8-sig") as f:
rows = list(csv.DictReader(f))
print(json.dumps(rows, indent=2, ensure_ascii=False))
The csv module handles quotes and embedded line breaks correctly. Note that every value stays a string; converting types is up to you. The utf-8-sig encoding strips a byte order mark if one is present.
Node.js
Node has no built-in CSV parser. Use a well-tested library rather than split, and check its options for delimiter detection and type casting.
For recurring imports, code is the better choice: you can validate each row and fail loudly. For one-off conversions and quick checks, a browser tool is faster.
Troubleshooting
Everything is in one field
The delimiter is wrong. A semicolon-separated file parsed as comma-separated produces one long field per row. Choose the delimiter manually.
Numbers became strings, or strings became numbers
Toggle Typed values. If only some columns should be numeric, convert with typing off and let the receiving code cast the columns it needs. Generating a schema with JSON to TypeScript or the JSON Schema Generator helps you document which fields are which.
Extra empty objects at the end
Trailing blank lines are removed automatically, but rows containing only delimiters (,,,) are real rows with empty values. Delete them in the sheet before exporting.
Strange characters in names
The file was probably saved in a legacy encoding. Re-export as UTF-8, or open it in a text editor and save it with UTF-8 encoding. The CSV & Excel Viewer is a quick way to check how a file reads before converting.
Frequently asked questions
How do I convert Excel to JSON?
Save the worksheet as CSV UTF-8 first, then paste or open the CSV in the converter. Each row becomes a JSON object keyed by the header row.
Why did my ZIP codes lose their leading zero?
Some converters and spreadsheets treat them as numbers. Our tool keeps values with leading zeros as strings, but if the zero was already lost in Excel before export, it is gone from the CSV too.
Can I convert a CSV without a header row?
Yes. Turn off First row is header and each row becomes an array of values instead of an object.
Does it handle commas and line breaks inside fields?
Yes, as long as those fields are wrapped in double quotes, as spreadsheet exports do automatically.
How do I go back from JSON to CSV?
Use the JSON to CSV Converter, which also flattens nested objects into columns.