CSV Escape Online — RFC 4180 Field Quoting

Quote CSV fields containing ,, ", or newline and double internal quotes per RFC 4180. Browser-only — paste raw values, copy CSV-safe output.

What is CSV Escaping?

CSV escaping is the process of wrapping fields that contain a delimiter (comma), double-quote, or newline in surrounding double quotes — and doubling any internal double quote — so the resulting row parses unambiguously per RFC 4180. Without it, a single comma inside a field shifts every subsequent column.

CSV looks deceptively simple but its edge cases — embedded newlines, quotes inside quoted fields, locale-specific delimiters — are responsible for a long history of broken imports. The OpenFormatter CSV escape tool runs entirely in JavaScript on your machine: paste rows, click Escape, copy a CSV-safe output that imports cleanly into Excel, Google Sheets, Postgres COPY, and any RFC 4180 parser.

How to escape CSV online — 4 steps

  1. Paste your raw rows. Drop CSV-style content into the Input panel. The tool processes each line and each comma-separated field independently.
  2. Click Escape. Each field is checked for the three trigger characters (,, ", newline). Triggered fields get wrapped in double quotes and any internal quotes are doubled.
  3. Verify the result. Plain fields stay unchanged; fields with commas, quotes, or newlines are now safely quoted. The structure stays row-aligned.
  4. Copy and import. Paste the escaped output into your .csv file, database COPY command, or spreadsheet import without worrying about misaligned columns.

Sample input and output

Raw input

name,note,city
Alice,She said "hi" today,New York
Bob,Lives at 123 Main St, Apt 5,Boston
Carol,Multi-line
note value,Chicago

RFC 4180 escaped

name,note,city
Alice,"She said ""hi"" today",New York
Bob,"Lives at 123 Main St, Apt 5",Boston
Carol,"Multi-line
note value",Chicago

RFC 4180 Compliant

Quotes fields containing comma, quote, or newline; doubles internal quotes — the exact convention every spreadsheet, database, and BI tool understands.

Smart Quoting

Plain alphanumeric fields stay unquoted, keeping output compact. Only fields that need quoting get it — no over-escaping.

Browser-Only

CSV often contains PII or financial data. The escape runs in your browser — paste, click, copy. Nothing is uploaded.

Common use cases

  • check_circleExporting database rows to CSV where address or comment fields contain commas
  • check_circlePreparing customer data with quoted product reviews for spreadsheet import
  • check_circleBuilding CSV from JSON or API responses that contain free-text descriptions
  • check_circleEncoding multi-line address blocks into a single CSV cell value
  • check_circleSanitising user-entered names with embedded quotes (O'Brien-style)
  • check_circleGenerating CSV from log lines that contain commas in the message field
  • check_circlePreparing data for COPY FROM in Postgres or BULK INSERT in SQL Server
  • check_circleEncoding survey free-text responses for analytics platforms that consume CSV

CSV escape vs JSON escape vs SQL escape

All three serialise text safely, but each targets a different parser. CSV escape wraps fields in double quotes when they contain commas, quotes, or newlines and doubles internal quotes — there is no backslash. JSON escape uses backslash sequences (\", \n, \u00xx) inside double-quoted strings per RFC 8259. SQL escape typically doubles single quotes (O''Brien) and varies by dialect. Using the wrong scheme breaks import: a backslash-escaped CSV produced by a JSON serializer will fail in Excel.

Need to reverse or convert?

Strip RFC 4180 quoting with CSV Unescape, or transform CSV into other formats with the rest of OpenFormatter's toolkit.

Frequently Asked Questions

When does a field need quoting per RFC 4180?

A CSV field requires quoting when it contains the delimiter (comma), a double-quote character, or a CR/LF newline. Plain alphanumeric fields and ones containing only spaces in the middle stay unquoted. Leading or trailing whitespace is also a strong reason to quote — many parsers strip surrounding whitespace from unquoted fields.

How are embedded newlines handled?

A field containing a CR, LF, or CRLF must be wrapped in double quotes. Inside the quotes the newline is written as a literal newline byte — not as a backslash-n sequence. The CSV row continues on the next physical line, and the field only ends at the matching closing quote, which is how Excel and Google Sheets store multi-line cells.

Why are internal double quotes doubled?

RFC 4180 has no backslash escape — instead a literal double quote inside a quoted field is written as two consecutive double quotes. So `say "hi"` becomes `"say ""hi"""`. This convention round-trips cleanly through Excel, LibreOffice, and every mainstream CSV parser.

Does this tool change the delimiter?

No. The tool assumes comma-delimited CSV — the format defined by RFC 4180 and what most exports use. If your file uses semicolon (common in European locales) or tab (TSV), the same quoting rules apply but you would substitute the delimiter character.

Should I quote every field to be safe?

You can — RFC 4180 explicitly allows quoting fields that do not strictly require it. Some teams prefer quoting every text field for consistency. The downside is larger file size and more visual noise; the upside is no edge cases when fields later acquire a comma or quote.

How are leading zeros and numeric IDs preserved?

CSV is plain text — quoting does not change a value's type. Spreadsheet apps like Excel re-interpret unquoted strings that look numeric and may strip leading zeros from `00123`. Quoting `"00123"` does not stop Excel from doing this on import; the only reliable fix is to use a leading apostrophe or import as text.

Is the data uploaded to your servers?

No. The escape transformation runs entirely in JavaScript inside your browser. CSV often contains PII, customer records, or financial data — no part of the input or output leaves the device. You can verify this in the browser DevTools Network tab when you click Run.

What is the difference between CSV escape and CSV unescape?

Escape adds RFC 4180 quoting around fields that need it and doubles internal quotes — it converts raw values into the form a CSV file expects. Unescape reverses the operation: it strips outer quotes and converts doubled quotes back to a single quote, restoring the original cell value.

CSV Escape Online — RFC 4180 Field Quoting | OpenFormatter