JSON Stringify Text and JSON Escape
JSON Stringify Text and JSON Escape
This tool converts text into a JSON string, escaping the characters JSON does not allow inside a string. Enter your text or JSON on the left and the stringified version appears on the right, ready to copy and paste. To go the other way, press the swap button between the panels and paste a JSON string to turn it back into plain text, which is what the JSON Unstringifier does by default.
New lines are converted to \n symbols, tabs become \t symbols, and the entire output is wrapped in quotation marks. This is exactly the format required when embedding text values inside JSON data structures. Untick Wrap in quotes to get the escaped text alone, for pasting between quotes that are already in your code.
What does JSON stringify do to text?
JSON stringify converts plain text into a JSON-safe string by escaping special characters. Newlines become \n, tabs become \t, double quotes become \", and backslashes become \\. The entire result is wrapped in double quotation marks so it can be safely embedded as a value in a JSON object or array. This ensures that whitespace, line breaks, and other control characters are preserved when the text is stored or transmitted as JSON data.
When would I need to stringify text for JSON?
Stringifying text is necessary whenever you need to include multi-line content or text with special characters inside a JSON structure. Common scenarios include preparing API request bodies that contain formatted text, embedding HTML templates or email content within JSON payloads, storing user-generated content in JSON-based databases, and building configuration files where values include line breaks or quotation marks. Without proper stringification, these special characters would break the JSON syntax and cause parsing errors. To reverse the process, use the JSON unstringifier. You can also tidy up your JSON output with the JSON formatter.
JSON string escape sequence reference
| Character | Escaped form | Notes |
|---|---|---|
Double quote " | \" | Required inside a JSON string |
Backslash \ | \\ | Required; a single backslash means an escape sequence follows |
| Newline | \n | Line Feed (LF), U+000A |
| Carriage return | \r | Carriage Return (CR), U+000D; Windows line endings are \r\n |
| Tab | \t | Horizontal Tab, U+0009 |
| Form feed | \f | Rarely encountered in practice |
| Backspace | \b | Rarely encountered in practice |
| Unicode character | \uXXXX | For any character not in ASCII range; e.g. \u00A9 for the copyright symbol |
What are common scenarios for JSON stringification?
Multi-line text in a JSON payload - If you are sending a body of text (e.g. an email template, a terms and conditions block, a blog post) as a JSON API parameter, line breaks must be escaped as \n. This tool handles that conversion automatically.
HTML in JSON - HTML content inside a JSON string requires escaping of double quotes (which appear in HTML attributes) and backslashes. Paste your HTML template into this tool and copy the stringified output directly into your JSON structure.
JavaScript string literals - When embedding a JSON string as a JavaScript variable value, the same escape rules apply. The output from this tool is ready to paste as a JavaScript string literal.
Configuration files - Many configuration systems (e.g. .env files loaded as JSON, AWS Lambda environment variables) require that multi-line values be stringified.
What is the difference between JSON.stringify() and this tool?
JavaScript's JSON.stringify() method converts a JavaScript value (object, array, string, number) into a JSON string. This tool specifically handles the string escaping part, converting a plain text string into a JSON-safe string literal. If you are working in a browser console, JSON.stringify("your text here") produces the same result.
Why does my stringified text have \r\n instead of just \n?
Your original text uses Windows-style line endings (Carriage Return + Line Feed). Both are valid in text files but \n alone is the more common convention in JSON payloads. If you need \n only, normalize your text to Unix line endings first by using the line break tool.
What is the difference between JSON escape and JSON stringify?
For a piece of text they do the same escaping: quotes become \", backslashes become \\, and line breaks and tabs become \n and \t. Stringifying also wraps the result in double quotes, so it is a complete JSON string value. Escaping usually means the characters alone, without the outer quotes, for text you will paste between quotes that already exist. Tick or untick Wrap in quotes to get either one.
Can I reverse the process (unescape a JSON string)?
Yes. Press the swap button between the panels and paste the escaped string, with or without its outer quotes, to get the plain text back with real line breaks. The JSON Unescape and Unstringifier does this by default.
Related JSON and encoding tools
- JSON Formatter - Format and beautify JSON
- JSON Unstringifier - Reverse JSON string escaping
- Base64 Encoder/Decoder - Convert between Base64 and plain text
- URL Encode/Decode - Percent-encode strings for URLs
- YAML Formatter - Format YAML documents
Last reviewed: September 2026