Special characters inside JSON strings — quotes, backslashes, newlines — must be escaped with a backslash, or the parser breaks. This is one of the top causes of the "Unexpected token" error. This guide covers every character that needs escaping.

Why escaping is necessary

JSON strings are wrapped in double quotes. When your value itself contains a double quote, the parser thinks the string ended early. Escaping with a backslash tells the parser the character is part of the string.

// Invalid — inner quote ends the string early
{"quote": "She said "hello""}

// Valid — escaped
{"quote": "She said \"hello\""}

The complete list of escape sequences

  • \" — double quote
  • \\ — backslash
  • \/ — forward slash (optional)
  • \n — newline
  • \r — carriage return
  • \t — tab
  • \b — backspace
  • \f — form feed
  • \uXXXX — any Unicode character by hex code point

The two most common mistakes

1. Unescaped newlines

JSON strings cannot contain raw line breaks. Pasting a multi-line address into a value breaks at the first newline.

// Invalid
{"address": "123 Main St
Apt 4"}

// Valid
{"address": "123 Main St\nApt 4"}

2. Unescaped backslashes (Windows paths)

// Invalid
{"path": "C:\Users\Alice"}

// Valid — each backslash doubled
{"path": "C:\\Users\\Alice"}

Escape & unescape JSON automatically

Paste any text and get a properly escaped JSON string, or reverse it. No manual backslash counting. Free and private.

Open tool →

Let your language do it for you

The best practice is to never escape manually. Every serializer handles it correctly:

// JavaScript
JSON.stringify({ quote: 'She said "hello"' });

// Python
json.dumps({"path": "C:\\Users"})

Escaping Unicode and emoji

JSON is UTF-8 by default, so emoji and accented characters work directly. For ASCII-safe output, use \uXXXX escapes. Emoji outside the Basic Multilingual Plane need a surrogate pair — two \uXXXX sequences.

JSON escaping vs HTML vs URL

JSON escaping is different from HTML escaping and URL encoding. If you embed JSON in an HTML attribute or URL, each layer has its own rules — do not mix them up.