Preserving a comma inside one CSV field
A comma can separate two fields or belong to the text of one field. This worksheet parses the same words with and without quotes and counts the resulting fields.
Two jobs for one character
In a comma-delimited file, the comma normally marks the end of a field. A value that itself contains a comma, such as a color list, a street address or a name written as surname, given name, would be split into pieces unless something protects it. The convention in the CSV specification, RFC 4180, is to wrap the whole field in double quotes. Inside quotes the comma is ordinary text. The parser used by the CSV to JSON converter follows this rule, so the same visible words can produce a different number of columns depending on whether the quotes are present.
The quoted version gives two fields
Enter "red, blue",green with header mode off. The first field begins with a double quote, so the parser reads everything up to the closing quote as one value, comma included. The result is one record with two fields: red, blue and green. The JSON output shows an array holding one inner array, and the first element contains the comma and the space after it. The quotes themselves are syntax and do not appear in the parsed value. RFC 4180, published in 2005, registered the text/csv media type and wrote down this convention after years of informal practice, so many spreadsheet and database tools write and read the same quoting. That is the right result for a source that meant a single field holding two colors. The check on the unquoted line below confirms the reverse case, so you can see both counts side by side.
The unquoted version gives three
Remove the quotes and enter red, blue,green. Now the first comma is a delimiter, so the record has three fields: red, then a field that starts with a space and reads " blue", then green. The converter keeps the leading space because it does not trim fields, so the second element in the output is the five characters space, b, l, u, e. A visual check can miss this, since a space before a word is hard to see. If your downstream code compares field text, an extra leading space makes "blue" and " blue" different values. Lookups against a list of allowed colors would fail for the second one. Trimming the fields in a later step is a separate decision, because some files use leading spaces on purpose.
Counting commas is not counting columns
A quick way to guess how many columns a row has is to count commas and add one. That works only when no field contains a quoted comma. In the quoted example above there are two commas in the text, yet there are two fields, not three. Always inspect the parsed array to see the real field count. The reverse mistake also occurs: a row such as a,,b has two commas and three fields, one of them empty, so a count that ignores empty fields undercounts. When a spreadsheet import shows too many columns, look for places where a descriptive text field lost its quotes during an earlier edit. When it shows too few, a quote may have been opened and never closed, which makes the parser read to the end of the file as one field.
Using header mode with a quoted comma
Header mode treats the first row as property names and builds one object per later record. Try city,note on the first line and Paris,"cold, wet" on the second with header mode on. The result is a single object where city is Paris and note is "cold, wet". Because the comma lives inside the quotes, the record still has two fields and matches the two header names. Without the quotes the record would have three fields, and the converter would reject it because the row width differs from the header width. That rejection is useful, since it points you to the row that needs quotes rather than assigning the shifted values to the wrong properties.
Quotes inside quoted fields
A value can contain a double quote as well as a comma. RFC 4180 handles that by doubling the quote character inside a quoted field. The input "say ""hi""",x is read as two fields: say "hi" and x. The outer quotes mark the field boundaries, and each doubled pair becomes one literal quote. In the JSON output the literal quote shows up with a backslash escape, because JSON strings escape double quotes. Forgetting to double the inner quotes is a common cause of fields that end early or of rows that swallow the following lines.
Dialect differences keep the same idea
Some regions use a semicolon as the field separator because the comma is the decimal mark, and a spreadsheet exporting in such a locale may produce semicolon-separated files with a .csv extension. This worksheet uses the comma-delimited dialect supported by the converter. A semicolon-delimited export needs a different parser setting, or the whole row may load as one field. Tab-separated files follow a similar logic with a different delimiter. If a file looks right in a text editor but loads as a single column, check which separator it actually uses before changing the data.
What a successful conversion tells you
A parse that finishes without an error confirms that the text follows CSV quoting rules and that every record has the same width. It does not confirm that the columns match what your system expects, that a quoted field was meant to be quoted, or that a missing quote was not simply a typing slip. Compare the parsed field count and a sample of values with the source document before loading the converted data anywhere that matters.
Fixing a file that lost its quotes
When you must repair a file where commas inside text were left unquoted, work from the structure of the rows. Find the rows with more fields than the header and look at where the extra pieces occur, since they usually sit in one text column. Wrap the whole value of that column in double quotes, and double any quote characters that appear inside it. Test a few repaired rows in the converter with header mode on, where a row of the wrong width is rejected, and then run the whole file. Where a source system allows it, correct the export itself so that the quoting is added consistently from the start.
Reproduce the checks
Quoted comma
Open the Csv To Json Converter and enter:
- CSV input
"red, blue",green- First row contains headers
false
Expected output:
Rows
[
[
"red, blue",
"green"
]
]The embedded comma remains inside the first value.
Unquoted comma
Open the Csv To Json Converter and enter:
- CSV input
red, blue,green- First row contains headers
false
Expected output:
Rows
[
[
"red",
" blue",
"green"
]
]There are three fields; the leading space is retained.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08