JSON Escape Sequences and Unicode Handling
Backslashes, quotes, and \uXXXX escapes cause subtle JSON parse failures. Learn valid escape sequences and how to debug Unicode in API strings.
Strings are where JSON looks simple but breaks often. Escaping rules exist so parsers can delimit "..." unambiguously. One wrong backslash or a raw newline inside a string fails the entire document.
Valid escape sequences in JSON strings
Inside double quotes, \ introduces:
| Escape | Meaning |
|--------|---------|
| \" | Double quote |
| \\ | Backslash |
| \/ | Solidus (optional) |
| \b | Backspace |
| \f | Form feed |
| \n | Line feed |
| \r | Carriage return |
| \t | Tab |
| \uXXXX | Unicode code point (4 hex digits) |
Anything else after \ is invalid in standard JSON — a frequent error when copying from languages with \' or \x hex escapes.
Quotes inside strings
{ "message": "She said \"hello\"" }
Never use single-quoted JSON strings.
Unicode: literal vs escaped
These are equivalent for U+00E9:
{ "city": "Montréal" }
{ "city": "Montr\u00e9al" }
Parsers normalize to the same string value. Byte size on the wire differs — minified UTF-8 may be smaller than \u escapes for non-ASCII.
Surrogate pairs and astral characters
Emoji and rare scripts may appear as:
{ "icon": "\uD83D\uDE00" }
(two \u escapes forming one UTF-16 surrogate pair in some serializers)
If validation fails on emoji, check whether your pipeline double-encodes or splits pairs.
Control characters
Raw control chars (U+0000–U+001F) inside strings are invalid unless escaped. Log pipelines sometimes inject raw tabs or bell characters — hex dump the bytes around the error offset.
Common copy-paste failures
- Windows paths:
C:\new—\nis interpreted as escape start → useC:\\newor forward slashes - Regex patterns: every
\must become\\in JSON - Smart quotes from Word/Slack
- Truncated
\u00(incomplete escape)
Debugging workflow
- Paste into JSON Validator; note character index in error.
- Jump to that offset; inspect preceding
\. - Replace raw newlines with
\n. - Re-format to confirm readable Unicode output.
Producing safe JSON from code
- Use
JSON.stringifyin JavaScript — do not build strings manually - In Python,
json.dumpswithensure_ascii=Falsefor UTF-8 files - Avoid concatenating user input into JSON strings without escaping
Related: common syntax errors.
Try this in BracketView
Open the BracketView workspace — core tools run in your browser.
Related BracketView tools
Related articles
- Common JSON Syntax Errors and How to Fix Them
Unexpected token, trailing commas, unescaped strings — learn what causes the most common JSON parse errors and how to fix them with a validator workflow.
- How to Validate JSON Against a JSON Schema
Step-by-step guide to validating JSON documents against JSON Schema — draft versions, common keywords, and worked examples for API payloads.
- Debugging Malformed API Responses: A Step-by-Step Guide
When an API returns broken JSON, use this workflow — capture, isolate, validate, compare to schema, and fix at the source — without guessing at syntax errors.