Code Beautify / MULTIVERTO

Escape JavaScript string

Escape JavaScript text as a JSON-compatible, double-quoted literal. See how quotes, backslashes and newlines behave when another layer is added.

Live converterYour input stays in this browser. No text is uploaded for conversion.

The file stays in your browser.
Chain tools

Apply each text tool to the previous result. Text workflows ↗

Only the recipe name and tool order are saved in this browser. Your input and results are never saved.

01 / Example

Example

Your inputHello Welcome
Result"Hello\nWelcome"

02 / Guide

Escape JavaScript string — How it works

What changes in this tool

Turn text into a quoted JavaScript string literal. The result is a complete quoted JavaScript-compatible string literal. New lines, quotation marks and backslashes receive escapes, while ordinary Unicode text remains readable. Copy the outer quotes too; removing them changes the output from a literal into source text.

Know the format

Here the source is data to be placed inside a string expression. The separate string-escape operation treats all input as data and serializes it as one quoted literal; it does not run the text as code. In either case, copied output should be checked in the destination parser and test environment.

A dependable workflow

Treat every input character as data to serialize into one quoted JavaScript-compatible string literal. The converter follows JSON string escaping, so quotes, backslashes and control characters receive escapes while the surrounding quotation marks become part of the result. It also escapes line separators that could be troublesome in source text. Paste a short phrase containing punctuation and a real line break to inspect the difference between visible escapes and the underlying text. This operation does not format or run JavaScript code; a source fragment pasted here becomes a string value representing that fragment. In the live example, with line breaks shown as JSON escapes, input "Hello\nWelcome" produces output "\"Hello\\nWelcome\"". Enter text containing a real newline, a tab and a double quote. The output should be one quoted literal with escape sequences where needed. Paste that literal into a small JavaScript test and compare its runtime string to the original text, character for character.

Check the result

Create a quoted JavaScript string literal from text copied out of a document or log. Try a line break, double quote and backslash, then evaluate or parse the literal in your destination context. Keep the outer quotation marks. Escaping a value for a JavaScript expression does not also make it safe for HTML, a URL or SQL. Parse the literal with a JSON-compatible string reader and compare the recovered text character by character with the input. A correct round trip checks the string representation, not whether the literal is safe inside HTML, a URL, a shell command or another surrounding language. Apply the destination’s own escaping rules when embedding it elsewhere. Preserve the outer quotation marks when using it as a standalone expression; remove them only if the receiving API explicitly expects the interior content. Inspect copied line breaks and backslashes, which are easy to confuse with their escaped spellings.

How to escape JSON quotes and backslashes

This tool returns a complete double-quoted string literal using JSON-compatible escaping; it does not return only the characters between the quotes. For example, input She said "hi" produces output with outer double quotes and backslashes before the inner quote marks. An input backslash becomes two backslashes in the literal, and a line break is represented by a backslash-n escape. The implementation uses JSON.stringify and also escapes the Unicode line and paragraph separators. If you place this result inside another quoted string or JSON document, that additional layer needs its own escaping. Do not run the same escaping step twice by accident.

How this conversion transforms the input
Text — Input
Read and transform structure
JavaScript — Result

Explore guides

Conversion guides

Explore guides