You want to embed a sentence containing quotation marks and a line break inside a JSON value. Pasting it as it is produces invalid JSON. It has to be escaped first.
What gets escaped
Inside a JSON string, a double quote becomes \", a backslash becomes \\, a new line becomes \n and a tab becomes \t. Control characters are written as \uXXXX sequences.
In the JSON Escape/Unescape tool, the text
She said "hi" (then a new line) new line\path becomes She said \"hi\"\nnew line\\path. You can drop that straight between two quotation marks in a JSON document.
Using the tool
- Choose escape to turn plain text into a JSON-safe string, or unescape to reverse it.
- Paste the text and copy the result.
The output does not include the surrounding quotation marks, so add them yourself when you build the document. If you unescape text that is not validly escaped, for example a lone backslash, the tool explains what is wrong instead of guessing.
Where this comes up
- Putting multi-line text, HTML or code into a JSON field.
- Reading a log line where a JSON string has been escaped twice, which leaves every quote preceded by a backslash.
- Preparing a message body for an API request.
Common mistakes
- Escaping text that is already escaped, which doubles every backslash.
- Forgetting that forward slashes need no escaping, although
\/is also allowed. - Using single quotes, which JSON does not allow.
To check the final document, run it through the JSON validator.
Frequently asked questions
Do I need to escape non-English characters?
No. JSON supports Unicode directly, so accented letters and other scripts can stay as they are.