CalculatorsConvertersDeveloperTextAll toolsDirectory
Submit your tool Sign in
Theme
Home/Answers/Developer
How-to

How do I escape a string so I can put it inside JSON?

Short answer

Backslash-escape the characters JSON reserves: double quotes become \", backslashes become \\, and literal newlines must become \n, since raw line breaks are not allowed inside a JSON string. A browser-based JSON escape tool converts any text into a safe JSON string literal, and unescapes it back, entirely on your own device.

Why pasting text into JSON breaks

JSON strings are delimited by double quotes, so any quote inside the text ends the string early, and the format forbids raw control characters such as literal newlines and tabs. That is why pasting a multi-line message or an HTML snippet into a JSON payload produces a parse error. The fix is escaping: quotes, backslashes and control characters are replaced with backslash sequences, and anything else can be written as a \u unicode escape.

Escape and unescape locally

A JSON string escaper takes your raw text, a log line, an error message, a snippet of HTML, and outputs a valid JSON string literal you can drop into a payload, a fixture or a config file. The companion unescape direction turns an escaped string from an API response or a log back into readable text with real line breaks. Both run entirely in your browser, so payload contents are never sent anywhere.

Step by step

  1. Paste the raw text. Open the JSON escape tool and paste the text that needs to go inside a JSON string.
  2. Copy the escaped literal. Copy the output, a valid JSON string with quotes, backslashes and newlines escaped.
  3. Drop it into your JSON. Paste the literal into your payload or fixture; it will now parse cleanly.

Frequently asked questions

Which characters does JSON require escaping?

Double quotes and backslashes always, plus control characters like newlines and tabs, which become sequences such as \n and \t.

Can I reverse an escaped string?

Yes. The unescape direction decodes backslash sequences back into readable text with real line breaks.

Is my text uploaded?

No. Escaping and unescaping run entirely in your browser.

Related answers