Why escape text in JSON?
Escaping JSON is necessary when you want to include special characters in a JSON string. JSON has specific rules for how certain characters must be represented to maintain valid syntax. For example, double quotes (") must be escaped with a backslash (\") because unescaped double quotes are used to delimit strings in JSON.
Examples of JSON escaping
Original text
This is a "JSON string" with special characters:
Backslash: Newline:
Tab:
Quotes: "Hello" and 'World'
Control chars:
Unicode: 😀 ñ € ä½ å¥½Escaped text
This is a \"JSON string\" with special characters:\nBackslash: Newline: \nTab:\t\nQuotes: \"Hello\" and 'World'\nControl chars: \b\f\n\r\t\nUnicode: 😀 ñ € ä½ å¥½Common JSON escape sequences
| Character | Escape Sequence | Description |
|---|---|---|
| " | \" | Double quote |
| \ | \\ | Backslash |
| / | \/ | Forward slash |
| Backspace | \b | Backspace character |
| Form feed | \f | Form feed character |
| Newline | \n | Line feed character |
| Carriage return | \r | Carriage return character |
| Tab | \t | Tab character |
| Unicode character | \uXXXX | Unicode character (where XXXX is the hex code) |
When to use JSON escaping
- When creating JSON strings programmatically
- When manually constructing JSON data that includes special characters
- When preparing user input to be included in JSON data
- When working with APIs that require JSON-formatted data
- When storing text that contains control characters or quotes in JSON format
This tool uses JavaScript's built-in JSON.stringify() function to properly escape text according to the JSON specification. The result can be safely included as a string value in a JSON document.
Tip:
When working with JSON, always validate your JSON after escaping to ensure it's properly formatted. Invalid JSON can cause errors in applications that try to parse it.
Related Tools
- Unescape JSON - Convert escaped JSON strings back to their original form
- Escape JavaScript - Escape text for use in JavaScript strings
- Minify JSON - Remove whitespace and format JSON for production
- Convert JSON to YAML - Convert between JSON and YAML formats
- Sort JSON - Sort JSON objects by keys
All Tools
See all available tools