How to Escape Text for JSON Strings
JSON Escaping
When to Escape JSON Strings
Escape raw text when embedding user input, multiline content, or special characters inside JSON payloads, environment variables, or test fixtures.
Real-World Examples
hello → "hello"
Newlines and tabs escaped as \n and \t
Quotes escaped for safe inclusion in JSON documents
Common Mistakes
- Manually escaping quotes and missing backslashes
- Double-escaping already escaped strings
- Forgetting that JSON.stringify adds surrounding quotes
Developer Tips
- JavaScript:
JSON.stringify(value)for string literals - Use escaped output when building JSON by string concatenation (prefer structured builders instead)
Frequently asked questions
Does output include surrounding quotes?
Yes. The result is a valid JSON string literal including opening and closing double quotes.
Can I escape non-text values?
This tool escapes plain text input. For objects or arrays, use the JSON formatter instead.
How do I reverse escaping?
Use the JSON Unescape tool to convert escaped string literals back to plain text.