Putting any text inside a JSON string safely
A JSON string starts and ends with a double quote, so a double quote inside it would end the string early. A backslash starts an escape, so a lone backslash inside it changes the meaning of the next character. And a raw line break is not allowed inside a string at all. These three rules are why pasting a paragraph, a stack trace or a Windows path into a JSON file so often breaks it. Escaping rewrites each problem character as a short sequence that starts with a backslash: \" for a quote, \\ for a backslash, \n for a line break and \t for a tab.
This tool uses the browser's JSON.stringify to do it. That matters because there are edge cases a hand-written find and replace usually misses. Carriage returns from Windows text become \r. Control characters that you cannot see, such as a NUL byte or an escape character copied from terminal output, become \u0000 or \u001b. Unpaired halves of an emoji, which can appear when text was cut in the wrong place, are written as \u escapes instead of producing invalid output. The result is exactly what a JavaScript program would write, so any JSON reader accepts it.
Two choices shape the output. The first is the surrounding quotes. With them, the result is a complete JSON value you can paste after a key and a colon. Without them, you get only the inside of the string, which is what you want when the quotes are already in your file and you are filling in the gap between them. The second is what happens to letters outside plain ASCII. JSON is Unicode, so é, ü, 日本 and emoji can stay as they are, and usually should, because the file stays readable. Writing them as \u escapes makes the file pure ASCII, which is safer when it passes through older systems that damage other characters.
With \u escapes on, an emoji becomes two escapes, such as \ud83d\ude00 for a grinning face. JSON escapes count UTF-16 code units, and characters beyond the first 65,536 need two of them, called a surrogate pair. Every JSON reader joins the pair back into one character, so nothing is lost.
Escaping is one half of a round trip. When you find a string full of \n and \" in a log line or an API response and want to read it as normal text, JSON Unescape does the reverse. Both tools run in your browser, so you can escape private messages, credentials in a config or customer data without sending them to a server.