GoToolsOnline Blog How-To All Tools

Fixing CSV Files Where Commas Live Inside the Data

An address or a price with a comma can shift every column out of place. Here is why it happens and how to fix it for good.

By Ben Praveen J ยท Published October 24, 2026

You open a customer export and the columns are wrong from row 37 onward. The city is sitting in the address column, the postcode has moved under "phone", and a new unnamed column has appeared at the end. Nine times out of ten the cause is the same: a value somewhere contains a comma, and whatever wrote or read the file treated that comma as a column break.

This guide explains why that happens, the quoting rules that prevent it, how to repair a file that is already broken, and how to stop it happening at export time. The examples below were run through our free CSV to JSON converter, so the outputs are real, not idealised.

The problem: when a comma is data, not a separator

CSV has no column markers other than the delimiter itself. Each line is a record, and each comma starts a new field. That works until the data contains the delimiter: an address like 12 Park Rd, Apt 4, a price written 1,299, a company called Smith, Jones & Co, or a free-text comment typed by a person. Here is a file where nobody protected the address:

name,address,city
Asha,12 Park Rd, Apt 4,Trichy

The header promises three columns, but the data line has four values. A strict reader has no way to know which comma was meant to be data. Our converter reads it exactly as written and returns:

[{"name": "Asha", "address": "12 Park Rd", "city": "Apt 4", "column4": "Trichy"}]

Nothing was lost, but everything after the address is one column to the right. The converter names the extra value column4 rather than dropping it, which is usually the first clue that something is off.

Why your rows suddenly misalign

Misalignment rarely affects every row. It starts at the first record whose value contains a comma and only affects that record, which is why a file can look fine at the top and fall apart halfway down. Common culprits:

  • Hand-built exports. A script that writes values.join(",") or string-concatenates fields never adds quotes.
  • Numbers with thousands separators. 1,299 becomes two fields, 1 and 299.
  • Locale differences. In much of Europe the comma is the decimal separator, so Excel saves "CSV" with semicolons instead: Widget;1,50. Open that with a comma reader and every row splits in the wrong place.
  • Line breaks inside a cell. A comment with Enter pressed in it becomes two lines. If the field is not quoted, the second half becomes a new, short record.
  • Copying between apps. Pasting a CSV into a word processor or chat app can turn straight quotes into curly ones, which are no longer CSV quotes.

The official fix: quoting fields

The closest thing CSV has to a standard, RFC 4180, solves this with double quotes. Any field may be wrapped in "...", and a field that contains the delimiter, a double quote or a line break must be. Inside the quotes, commas are just text:

name,address,city
Asha,"12 Park Rd, Apt 4",Trichy
[{"name": "Asha", "address": "12 Park Rd, Apt 4", "city": "Trichy"}]

Line breaks work the same way. This is one record with two fields, not two records:

id,notes
1,"line one
line two"

The converter returns {"id": 1, "notes": "line one\nline two"}. If you count lines with a simple tool such as wc -l you will get a higher number than the real record count, which is normal for files like this.

Two details trip people up. First, the quote has to be the first character of the field; a quote in the middle, as in 27" screen, is treated as an ordinary character (our converter keeps it as 27" screen), but stricter readers may reject it. Second, spaces outside the quotes matter to some programs. Our converter trims spaces around unquoted values and keeps spaces inside quotes, so " padded " stays padded.

How the escaping rules work (quotes inside quotes)

If quotes mark the edges of a field, how do you put a quote inside one? You double it. Each "" inside a quoted field means one literal ":

name,comment
Ravi,"He said ""hi"" twice"

That reads as the value He said "hi" twice. Backslash escaping (\") is not part of RFC 4180; Excel, Google Sheets and our converter do not treat a backslash specially, so files from tools that use it need the separate option those tools provide (for example the escapechar setting in Python's csv module).

The one mistake that cannot be guessed around is an unclosed quote. In Asha,"12 Park Rd, Apt 4 the field never ends, so everything after it, possibly the rest of the file, would become one giant value. Rather than return a silently mangled table, our converter stops with the error a quoted field is not closed (missing "), which tells you to look for a stray quote.

Repairing a CSV that's already broken

The best repair is a re-export from the original source with quoting switched on, because only the source knows where each value really ended. When that is not possible:

  1. Find the bad rows. Paste the file into our CSV to JSON converter with "First row is headers" ticked. The result line shows how many columns were read; if it is higher than your header count, search the output for the extra keys (column4, column5 ...) to see which records overflowed.
  2. Search by pattern. In the Regex Tester, a pattern like ^([^,]*,){3,}[^,]*$ with the multiline flag matches lines with more than two commas, which is every overflowing line in a three-column file that has no quoted fields yet.
  3. Fix the one column that holds commas. Usually only one field is free text, such as address or description. If it is the last column, you can wrap everything after the last expected comma in quotes. If it is in the middle, take the known number of fields from the left and from the right and quote what remains.
  4. Try another delimiter. If the file came from European Excel and looks like Widget;1,50, it is not broken, it is semicolon-separated. Auto-detect in our converter picks semicolon for it and keeps 1,50 as the string "1,50".
  5. Check the result. Convert again and confirm the column count matches the header and no columnN keys remain.

Keep a copy of the original before editing. Bulk find-and-replace on commas almost always does more damage than it fixes, because it cannot tell a separator from data.

Preventing it at export time

Almost every serious tool quotes correctly if you let it do the writing:

  • Excel and Google Sheets wrap any cell containing a comma, quote or line break in quotes when you save or download as CSV. In Excel, "CSV UTF-8" also keeps accented and non-Latin characters intact.
  • Python: use the csv module (csv.writer quotes only fields that need it by default) or pandas to_csv, never ",".join(row).
  • JavaScript: use a CSV library or an escape function that wraps fields containing the delimiter, quotes or newlines and doubles inner quotes.
  • Databases: PostgreSQL's COPY ... WITH (FORMAT csv) quotes as needed; MySQL's SELECT ... INTO OUTFILE needs FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'.

When the receiving side is fixed and you cannot change it, agree on a delimiter that never appears in the data, such as tab, and say so in the file name or documentation.

Converting to JSON to avoid the problem entirely

JSON does not have this problem, because every string is wrapped in quotes and every key is named, so a comma inside a value can never be mistaken for structure. If the data is going into an API, a NoSQL database or a JavaScript app, converting once and passing JSON along removes a whole class of bugs. For a longer comparison, see CSV vs JSON: which data format should you use?

Going the other way, our JSON to CSV converter quotes values for you. The record {"name": "Asha", "address": "12 Park Rd, Apt 4", "note": "He said \"hi\""} comes out as:

name,address,note
Asha,"12 Park Rd, Apt 4","He said ""hi"""

Both converters run in your browser, so the file you paste is not uploaded to our server.

Frequently asked questions

Why does Excel put all my data in one column?

The file uses a different delimiter from the one your Excel locale expects, for example commas on a system set to semicolons. Use Data, From Text/CSV and choose the delimiter, or convert the file with a tool that lets you pick it.

Do I have to quote every field?

No. Only fields that contain the delimiter, a double quote or a line break must be quoted. Quoting every field is also valid and some systems prefer it.

Can I just use a different delimiter instead of quotes?

Yes, if you are sure it never appears in the data. Tab and pipe are common choices. It moves the problem rather than solving it, so quoting is still the safer default.

How do I write a double quote inside a CSV value?

Wrap the field in double quotes and double the inner quote: "He said ""hi""" reads as He said "hi".

Try these free tools

No signup, no watermark โ€” works in your browser.

  • ๐Ÿ”„CSV to JSON
    Open tool โ†’
  • ๐ŸงฉJSON Formatter
    Open tool โ†’
  • ๐Ÿ”Regex Tester
    Open tool โ†’
  • ๐Ÿ“Online Notepad
    Open tool โ†’

โ† Blog index  |  Quick guides  |  All tools

We use cookies for analytics and to show ads. Learn more