JSON Quiet

Escape sequences in JSON strings

By Bruno J F Costa · The characters that must be escaped — and the ones that only look scary.

A JSON string is a sequence of characters between double quotes. Some characters cannot appear raw inside those quotes. They must be written as an escape: a backslash plus a code. If you skip the escape, the parser thinks the string ended, then the next letters look like garbage in the middle of an object. That is the usual “Unexpected token” in the middle of a sentence.

This page lists the escapes you actually meet. For accents and UTF-8 policy, use the Unicode guide. For a full error catalog, use common errors.

The required everyday escapes

Less common: \b (backspace) and \f (form feed). If you see them, they usually came from a binary-ish dump, not from prose.

\\uXXXX

A backslash, u, and four hex digits encode a Unicode code unit. \u00e9 is “é”. You do not need this for é if the file is UTF-8 — a literal é is fine. Use \u when the character is awkward to type, when you must stay in ASCII source, or when you are representing a control character that has no short escape.

Surrogate pairs (\uD83D\uDE00) encode some emoji in older emitters. A modern parser turns them into one character. Do not delete one half “to clean the file.”

The quote that closed too early

{"note": "He said "hello" and left"}

The parser sees a string He said , then the identifier hello, then chaos. The fix is:

{"note": "He said \"hello\" and left"}

If Validate reports a line and column in the middle of English text, look backward for an unescaped ". Fix the first one. Validate again. Parsers stop at the first problem; later quotes wait their turn.

Double-escaped hell

When JSON is embedded in another JSON string, backslashes multiply. A payload that contains a Windows path inside a message field can look like "C:\\\\temp" in the outer document. Format the outer document first. Copy the inner string value. If that inner text is itself JSON, paste it into a second pass and Format again. Do not try to count backslashes by eye in a minified log.

What you should not escape

Single quotes do not need a backslash in JSON (the delimiter is double quotes). Accents do not need \u unless you chose that style. Spaces do not need escapes. Escaping “everything that is not A–Z” makes review harder and does not make the document more valid.

Related guides

Unicode and UTF-8 · Common errors · Validate RFC 8259 · All guides

Validate a string-heavy payload →