JSON Escape / Unescape
Escape special characters in strings for JSON or unescape JSON strings back to readable text. Handles newlines, tabs, quotes, and backslashes.
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
| Character | Escape Sequence | Description |
|---|---|---|
| " | \" | Double quote - must be escaped inside JSON strings |
| \ | \\ | Backslash - escape character itself needs escaping |
| Newline | \n | Line feed - moves to the next line |
| Tab | \t | Horizontal tab - indentation character |
| Carriage return | \r | Return to start of line (Windows line endings) |
| Backspace | \b | Backspace character |
| Form feed | \f | Page break character (rarely used) |
| Unicode | \uXXXX | Any 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
JSON Prettifier
Format and pretty-print JSON with proper indentation online. Choose 2 spaces, 4 spaces, or tabs. Instant formatting with error detection and stats.
JSON Validator
Validate JSON syntax and find errors with line numbers online for free. Real-time validation as you type with detailed error messages and stats.
HTML Encoder / Decoder
Encode special characters to HTML entities or decode HTML entities back to text. Handles all named and numeric entities with live preview.
Related Tools
JSON Prettifier
Format and pretty-print JSON with proper indentation online. Choose 2 spaces, 4 spaces, or tabs. Instant formatting with error detection and stats.
💻 Developer ToolsJSON Validator
Validate JSON syntax and find errors with line numbers online for free. Real-time validation as you type with detailed error messages and stats.
💻 Developer ToolsHTML Encoder / Decoder
Encode special characters to HTML entities or decode HTML entities back to text. Handles all named and numeric entities with live preview.
💻 Developer Tools