JSON Stringify Text
Paste text, get a string literal that is safe to place inside JSON.
INPUT
CHARS: 0WORDS: 0LINES: 0
OUTPUT
CHARS: 0WORDS: 0LINES: 0
How the JSON Stringify Text works
The tool applies the same escaping as JSON.stringify: double quotes become backslash quote, line breaks become the two characters backslash n, tabs and control characters are escaped, and backslashes are doubled. The result can be pasted inside a JSON document as a value.
Optional switches wrap the result in double quotes, escape every non-ASCII character as a backslash u sequence for systems that need pure ASCII, or stringify twice for JSON that has to be embedded inside another JSON string.
JSON Stringify Text examples
Sample input with the default options
Input
She said "hi" Second line
Result
"She said \"hi\"\nSecond line"
When it is useful
- •Putting a block of HTML, SQL or code into a JSON field.
- •Preparing a message body for a REST API request.
- •Building test fixtures that contain multi line text.
- •Embedding one JSON document inside another.
Frequently Asked Questions
How do I reverse the process?
Use the JSON Unstringifier, which turns an escaped string back into the original text.
Why would I stringify twice?
Some APIs expect a JSON string whose content is itself JSON. The first pass makes the inner document a string, the second makes that safe to embed in an outer document.
Are emoji escaped?
Only if the ASCII option is on. Then they become surrogate pairs, such as backslash uD83D backslash uDE00.
Related tools
- JSON UnstringifierPaste a string full of backslashes and see the original content.
- JSON Formatter and MinifierPaste JSON to validate it and print it neatly, or compress it to a single line.
- JSON to YAML ConverterSwitch configuration between JSON and YAML in either direction.
- Find and Replace TextPaste text, enter what to find and what to put in its place, and see the result immediately.