Yueseryueser.com

← All guides

How to Wrap Text in Quotes (and Why CSV Escaping Is Different)

Text that goes into code, a JSON array or a chat reply needs quotes on both ends. Adding them per line and escaping the inner ones takes one step and removes the guesswork about matched pairs.

Open the tool:Wrap in Quotes

When you need matched quote marks

Writing test data often means turning a column of place names into JSON array elements. Adding the quotes by hand misses one sooner or later, and a single miss makes JSON.parse fail, after which every line has to be checked to find the gap.

The other case is quoting a passage in a document or a reply where the boundaries need to be explicit, or putting several sentences into a string array in code, where inner double quotes have to be escaped or the string ends early and the rest of the file stops parsing.

Line by line, escaped the JSON way

Each line is handled separately: a non-empty line gets a straight double quote at each end, inner double quotes become a backslash plus a quote, and empty lines stay empty. Three paragraphs therefore produce three quoted lines rather than one quoted block.

That escaping matches JSON and most programming language string syntax, but not CSV. CSV represents a quote inside a field by doubling it, not by a backslash, so pasting this output into a CSV breaks the field boundaries and the backslashes have to be replaced with doubled quotes.

Limits, and what to use instead

Only straight double quotes are added. There is no single quote, no Chinese corner bracket, no curly quote, and no way to quote selected lines only. Line breaks are not escaped into sequences either, so a multi-line block does not become one valid JSON string — it becomes a series of strings, one per line.

For one pair around a whole passage, join the lines first and quote afterwards. For CSV fields, export from a spreadsheet. For JavaScript template literals, backticks and dollar braces need handling too, which is outside what this tool does.

FAQ

Does it add curly or Chinese quotation marks?

No, only straight double quotes. Curly quotes and Chinese corner brackets belong to typography, and code, JSON and CSV need straight quotes or the parser rejects them. Replace the characters by hand afterwards if the typographic form matters.

How are multiple lines handled?

Each line is quoted on its own and empty lines are left empty, so the result is several quoted strings rather than one quoted block. Join the lines first if you need a single pair around the whole passage.

What happens to quotes already in the text?

Inner double quotes are replaced with a backslash plus a quote and another pair is added outside. If the source already carried quotes, the result has two layers, so check the nesting before using it.

Related tool:Wrap in Quotes