"category": "utility",
JSON Escape Tool
"tldr": Paste any text and get a valid JSON string literal - quotes, backslashes, newlines, and control characters escaped correctly.
Turn any text - including code snippets, SQL queries, HTML, or multi-line strings - into a valid JSON string literal. Quotes become \", backslashes become \\, newlines become \n, and control characters are converted to unicode escapes.
This is the tool you need when embedding a string inside a JSON payload by hand: pasting raw text with quotes or line breaks into a JSON document is the most common cause of "Unexpected token" parse errors.
How to escape text for JSON
- 1Paste your raw text into the input panel - multi-line content is fine.
- 2The tool wraps it in double quotes and escapes every character JSON requires.
- 3The output is a complete, valid JSON string literal.
- 4Paste it directly into your JSON document, request body, or code.
Convert Text to Escaped JSON string in code
const raw = 'Line one with "quotes"\nLine two';
const escaped = JSON.stringify(raw);
// => "\"Line one with \\"quotes\\"\\nLine two\""import json
raw = 'Line one with "quotes"\nLine two'
escaped = json.dumps(raw)
print(escaped)Frequently asked questions
Which characters does JSON require escaping?
Inside a JSON string you must escape the double quote (\"), the backslash (\\), and control characters below U+0020 - most commonly newline (\n), tab (\t), and carriage return (\r). Everything else, including unicode text and emoji, can appear literally.
Do I need to escape forward slashes?
No. Escaping / as \/ is allowed by the spec but never required. Some encoders do it to make JSON safe for embedding inside HTML <script> tags, which is why you sometimes see it in API responses.
Why does my JSON fail to parse after I pasted text into it?
Almost always an unescaped double quote or a literal line break inside a string - both terminate the string early and produce errors like "Unexpected token". Escaping the text with this tool before pasting fixes it.
How do I do this in code?
Every language has a built-in: JSON.stringify(text) in JavaScript, json.dumps(text) in Python, JsonSerializer.Serialize(text) in C#. This tool applies the same rules when you just need to fix a payload by hand.
Last updated:
You might also need
Free and in-browser, like everything on JSON Console. Browse all tools →