Escape quotes, backslashes and line breaks so text fits in a JSON string
Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.A JSON string cannot hold a raw double quote, a backslash or a line break: each must be written as \", \\ or \n, and other control characters as \u001f-style codes. Paste any text, a log line, an HTML snippet or a whole file, and get it escaped exactly as JSON.stringify would, ready to drop between quotes.
Paste the text into the Input pane.
Check that Escape and JSON are selected; the escaped text appears in the Output pane.
Turn on Add quotes if you want the result wrapped in double quotes, ready to use as a JSON value.
Click Copy and paste the result into your JSON.
Turn on ASCII only to write accents and emoji as \u codes too.
Every language that puts text between quotes needs a way to include the quote itself, the backslash and characters you cannot type, such as a line break. That is escaping. The rules differ slightly per language, and a string escaped for one can be wrong in another, so pick the language first.
Escape. Paste text and the escaped version appears as you type. JSON output matches what JSON.stringify writes, character for character. Turn on ASCII only to write accents and emoji as escape codes too, for systems that cannot carry UTF-8. Add quotes wraps the result so it is a complete literal.
Unescape. Paste the inside of a string, or the whole literal with its quotes, and get the text back. Each language's own rules apply: JSON refuses \x41, JavaScript refuses old octal escapes as strict mode does, Python keeps unknown escapes such as \d as written, and Java accepts \uuuu0041. The first invalid sequence is reported with its position.
The rest of the article, and all 6 questions about String Escape & Unescape, are on the String Escape & Unescape page.
Put a backslash before each double quote inside a JSON string, so He said "hi" is written as "He said \"hi\"". The backslash itself must also be doubled, as \\. Single quotes need no escaping in JSON, because JSON strings are always wrapped in double quotes.
Write \n where the line should break. JSON does not allow a raw line break inside a string, so a multi-line text must have every line break, and every tab, escaped as \n and \t. A Windows line ending becomes \r\n. Pasting a multi-line text here produces exactly that.
Backslashes everywhere usually mean the JSON was stored as a string inside other JSON, so its quotes became \" and its line breaks \n. Unescape it once with the JSON setting and you get the inner JSON back; if it still shows backslashes, it was escaped twice and needs a second pass.
Escaping marks special characters inside one format so they are read literally, such as \" inside a JSON string. Encoding rewrites the whole text into another form, such as Base64 or percent-encoding for URLs. An escaped string is still readable; an encoded one usually is not. Use the URL Encoder or Base64 tool for those jobs.
Rates and rules change; check the source before you rely on a figure.
Still stuck? Ask about String Escape & Unescape and anybody who knows can answer. No account needed.
Same job, other tools: Query String Parser – Split a URL query string into a table of decoded parameters · Base64 Decode – Turn Base64 back into text or a downloadable file · Base64 Encode – Turn text or a file into Base64 · TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON · JSON to YAML – Turn JSON into clean, readable YAML for configs.