CSV Escape / Unescape
Escapes or unescapes a CSV value, quoting values that contain commas, newlines or double quotes, and doubling embedded double quotes.
A value containing the delimiter must be enclosed in double quotes.
Ctrl + Enter
Result
CSV escaping explained
The CSV quoting rules (RFC 4180)
CSV has no official standard body, but RFC 4180 documents the behaviour that virtually every spreadsheet and library agrees on. A field is written as-is unless it contains a "problematic" character, in which case it is enclosed in double quotes:
- A field containing the delimiter (comma, semicolon, tab…) must be enclosed in double quotes, otherwise it would be read as two fields.
- A field containing a line break (CR or LF) must be enclosed in double quotes, otherwise it would be read as two records.
- A field containing a double quote must be enclosed in double quotes, and every embedded double quote is escaped by doubling it (
"becomes""). There is no backslash escaping in CSV. - Fields with leading or trailing spaces are quoted by this tool as well, because many readers trim unquoted fields.
- Any field may be quoted even when it is not required ("Always enclose in double quotes"). Some consumers, such as importers that must distinguish an empty string from a null value, prefer this.
Before / after
| Value | Escaped (comma delimiter) | Reason |
|---|---|---|
plain value | plain value | Nothing to escape |
Smith, John | "Smith, John" | Contains the delimiter |
He said "hello" | "He said ""hello""" | Contains double quotes |
12" screen | "12"" screen" | Contains a double quote |
| Two lines separated by a line break | "line one | Contains a line break (the break is kept literally inside the quotes) |
a;b with the semicolon delimiter | "a;b" | Contains the delimiter |
Unescaping
The unescape button removes the enclosing double quotes when present and turns every "" back into a single ". With "Treat each line as a separate value" checked, every line of the input is processed independently, which is convenient for a column of values pasted from a spreadsheet. Uncheck it to unescape a single multi-line value.
Good to know
- This tool escapes values. To build or parse whole files, use the CSV to JSON or CSV to XML converters, which handle rows, headers and delimiter sniffing.
- Excel in many European locales uses the semicolon as the default delimiter because the comma is the decimal separator.
- A value starting with
=,+,-or@can be interpreted as a formula by spreadsheets ("CSV injection"). Quoting does not prevent this; prefix such values with a single quote or a space when the file is meant to be opened in Excel. - The MIME type of CSV is
text/csv; the record separator recommended by the RFC is CRLF, although LF is universally accepted.