MyKit.tools

JSON Escape / Unescape

Escape special characters in strings for JSON or unescape JSON strings back to readable text. Handles newlines, tabs, quotes, and backslashes.

Mode:

What Is JSON Escaping?

JSON escaping converts special characters in a string into escape sequences that are safe to include inside a JSON value. Characters like double quotes, backslashes, newlines, and tabs have special meaning in JSON, so they must be preceded by a backslash to be treated as literal text rather than syntax.

For example, if you want to store the text He said "hello" inside a JSON string, the quotes around hello must be escaped as \" to avoid breaking the JSON structure. Without escaping, the parser would see the quote after said as the end of the string and fail with a syntax error.

Common JSON Escape Sequences

CharacterEscape SequenceDescription
"\"Double quote - must be escaped inside JSON strings
\\\Backslash - escape character itself needs escaping
Newline\nLine feed - moves to the next line
Tab\tHorizontal tab - indentation character
Carriage return\rReturn to start of line (Windows line endings)
Backspace\bBackspace character
Form feed\fPage break character (rarely used)
Unicode\uXXXXAny Unicode character by its 4-digit hex code

When Do You Need to Escape JSON Strings?

You need JSON escaping whenever you are embedding a raw string inside a JSON payload. This comes up frequently when building API request bodies, storing user-generated content in JSON fields, embedding HTML or code snippets inside JSON, and constructing JSON strings manually in code.

Most programming languages handle escaping automatically when you use their JSON serialisation functions (JSON.stringify in JavaScript, json.dumps in Python). Manual escaping is needed when you are constructing JSON by hand, debugging malformed payloads, or pasting content into a JSON file that was not generated by code.

Frequently Asked Questions

Why do double quotes need escaping in JSON?

JSON uses double quotes to delimit string values. If your string contains a literal double quote character, the parser would interpret it as the end of the string. The backslash before the quote (\" ) tells the parser to treat it as a regular character, not a string boundary.

What happens to newlines inside JSON strings?

Literal newline characters are not allowed inside JSON strings. They must be replaced with the escape sequence \n. If you paste multi-line text into a JSON string without escaping, the JSON will be invalid. This tool converts those newlines automatically.

Does this tool also unescape JSON strings?

Yes. You can switch between escape and unescape modes. Unescaping converts sequences like \n back to actual newline characters and \" back to plain double quotes, giving you the original readable text.

Related Tools