⇄LocalShift. Runs on your device
THE LOCALSHIFT FIELD GUIDE

CSV Quotes and Line Breaks: Escaping with Examples

A comma or line break inside a cell needs CSV quoting. A literal double quote inside a quoted cell is written as two double quotes. Use a parser rather than splitting the text on every comma.

Three cases that simple splitting breaks

A person's address may contain a comma, a note may contain a line break, and a quotation may contain quote characters. These are field contents, not necessarily record or column boundaries. RFC 4180 documents common CSV quoting conventions; actual producers can still differ.

In the example, each record has two columns even though one note spans two physical lines. Paste it into CSV to JSON to inspect the resulting strings.

name,note
Alex,"hello, world"
Sam,"He said ""yes"""
Lee,"line 1
line 2"

Expected values (spacing may differ)

[
  {
    "name": "Alex",
    "note": "hello, world"
  },
  {
    "name": "Sam",
    "note": "He said \"yes\""
  },
  {
    "name": "Lee",
    "note": "line 1\nline 2"
  }
]

When does a CSV field need quotes?

For comma-separated CSV, wrap a field in double quotes when it contains a comma, a double quote, or a line break. Inside that quoted field, double each literal quote. A backslash is not the CSV escape character.

Cell valueCSV representationReason
hellohelloNo special characters; quotes are optional.
hello, world"hello, world"The comma belongs to this cell.
He said "yes""He said ""yes"""Double the quotes inside the quoted field.
line 1 line 2"line 1 line 2"Keep the real line break inside the outer quotes.

A line break inside a cell is not a new record

The sample above contains three data records: Alex, Sam and Lee. Lee has one note containing a real newline. In JSON, that newline is displayed as \n inside the string. The two characters backslash and n typed into CSV would instead remain literal text.

To inspect a column without breaking multiline values, first parse the file with CSV to JSON and read the property with that column name in each object. Do not split the source on newline characters. This tool converts the full table; it does not provide a column-only export.

Match the delimiter to the source

If your file uses semicolons between fields, select Semicolon. A comma that appears as punctuation inside a semicolon-separated file is not the column separator. LocalShift also offers a pipe separator for CSV tools.

For TSV, the delimiter is an actual tab character. Typing a backslash followed by t does not insert a tab into a file.

Diagnose a row-count error

When rows have different numbers of fields, first inspect the delimiter and any unclosed quotes. Adding arbitrary commas to make the count match can move values into the wrong columns.

With headers enabled, column names must be nonempty and unique. If the first line is data rather than a header, disable the header option; CSV to JSON then exports arrays of values. Blank-only rows are skipped.

Export and inspect

CSV to TSV parses cells before changing separators, preserving a quoted comma as part of its original value. Output fields may still need quotes when they contain tabs or line breaks. Confirm your destination supports that form.

For spreadsheet-bound output, review formula-like cells and the spreadsheet-safe option. Keep an untouched copy of the source so you can compare important records after conversion.

References

General format references; LocalShift-specific behavior is documented and tested separately.

Try the tools