JSON String Escaper
Escape text into a safe JSON string — quotes, newlines and special characters handled.
Was this tool helpful?
Thanks for the feedback!
The JSON String Escaper turns any text into a valid JSON string literal: it wraps it in double quotes and encodes the characters that JSON does not allow raw, such as quotes, backslashes, line breaks and tabs. Use it when you need to put multi-line text, a Windows path or a block of HTML into a JSON file or request body by hand.
Example
The two-line input
Line one
She said "hi"
becomes
"Line one\nShe said \"hi\""
The real line break turned into \n and each double quote gained a backslash. A Windows path works the same way: C:\Users\asha becomes "C:\\Users\\asha", because a single backslash starts an escape sequence in JSON.
Tabs become \t, and invisible control characters are written as Unicode escapes: a bell character (code 7) hidden in copied terminal output shows up as \u0007. That makes the escaper a handy way to spot stray characters that break a parser elsewhere.
The escape rules, per RFC 8259
| Character | Escaped as |
|---|---|
| Double quote | \" |
| Backslash | \\ |
| Line feed / carriage return | \n / \r |
| Tab | \t |
| Backspace / form feed | \b / \f |
| Other control characters | \u0000 to \u001f |
Everything else is left as it is. Forward slashes are not escaped, and Hindi text, emoji and ₹ stay as readable characters rather than \u codes, since JSON is UTF-8 and allows them directly. The escaping is done by the browser's built-in JSON.stringify, so the result is exactly what JavaScript itself would produce.
A common real case: keys and certificates
Service-account files and many cloud settings store a PEM private key or certificate inside a JSON value. The key has real line breaks, which are illegal inside a JSON string. Paste the whole block, from -----BEGIN PRIVATE KEY----- to the end line, and the tool gives one line with \n in each place a break was. Only do this with keys you are allowed to handle, and avoid pasting production secrets into any web page when a local script will do.
Mistakes to avoid
- Doubled quotes. The output already includes the surrounding quotes. If you paste it into
"message": "", remove the empty pair first, or you'll get""text"", which is invalid. - Stray whitespace. The input isn't trimmed, so a trailing Enter becomes
\nat the end of the value. - Escaping twice. Running already-escaped text through again turns
\ninto\\n, which shows up literally as backslash-n in your app.
A JSON string is also a valid JavaScript string literal, so the output can be pasted straight into code. To reverse the process, use the JSON String Unescaper, and check the finished document with the JSON Validator.