Escape/unescape JSON strings: quotes, newlines, tabs, backslashes, Unicode. Convert text to JSON-safe string. Decode escaped JSON. Online JSON escaper.
Use this free online Escape / Unescape directly in your browser. No signup required, no data leaves your device. Part of Utilier — a collection of 133+ developer utilities.
What is JSON String Escape/Unescape (Quote, Newline, Unicode, Backslash)?
Prevent JSON syntax errors (unescaped quotes, newlines break JSON). Safely embed any text in JSON strings.
Fix JSON syntax errors: JSON: {"message": "He said "Hello""} (syntax error: unescaped quotes). Escaped: {"message": "He said \"Hello\""}. Quotes inside string must be escaped (\" not ").
Embed multiline text in JSON: Error message (3 lines): Line 1\nLine 2\nLine 3. JSON string: "Line 1\nLine 2\nLine 3" (\n = newline escape). Can't use actual newlines in JSON strings (breaks syntax).
API request payloads: POST API with user input: {"comment": "User said: \"Great!\"\nThanks"}. User input has quotes/newlines → escape before JSON. Prevents injection (malformed JSON breaks API).
Generate JSON from code: JavaScript: const msg = 'He said "Hi"'; const json = `{"message": "${escape(msg)}"}`; Without escaping: {"message": "He said "Hi""} (invalid JSON). With escaping: valid.
Debug escaped strings: API returns: {"error": "File not found:\nC:\\Users\\file.txt"}. Hard to read: \n and \\ mixed. Unescape: File not found: (newline) C:\Users\file.txt (clear message).
Config files (JSON): Store text with special chars: {"license": "MIT License\nCopyright (c) 2024"}. Newline in license text → escape as \n. JSON parser converts \n back to newline (when reading).
When to use json escape
Use when working with JSON strings containing special characters.
Creating JSON payloads (API requests with text containing quotes/newlines).
Fixing JSON syntax errors (unescaped quotes or newlines).
Debugging JSON responses (unescape to see actual text).
Generating JSON programmatically (escape variables before inserting).
Embedding multiline text in JSON (escape newlines as \n).
Storing config with special chars (JSON config files).
Testing JSON parsers (check handling of escape sequences).
Converting between escaped/unescaped formats (data transformation).
How to use json escape
Enter text, choose escape or unescape, copy result.
Escape text to JSON string: Mode: Escape. Enter: He said "Hello"\nNew line (quotes, backslash, text 'New line'). Output: He said \"Hello\"\\nNew line (" → \", \ → \\, \n stays \n). Copy result.
Copy for use in JSON: Escaped result: He said \"Hello\". Use in JSON: {"message": "He said \"Hello\""}. Or code: const json = '{"message": "' + escaped + '"}';
Validate result: After escaping: paste in JSON validator. Example: {"text": "escaped result"}. Validates: escaping correct (no syntax errors). Or test in JSON.parse('{"text": "..."}').
Forward slash handling: Optional: escape / → \/. JSON spec allows both (/ and \/). Most parsers accept /. Some require \/ (HTML script tags: </script> → <\/script> to avoid closing tag). Option to enable/disable.
Error detection: Invalid escape sequences flagged: \x (not valid JSON, should be \uXXXX), \' (single quote, not required in JSON), unterminated \u (\u00 missing 2 digits). Helps fix malformed escaped strings.
Real-time conversion: Type in input → output updates instantly. No submit button. See escaped/unescaped result as you type. Immediate feedback (test different inputs).
Common use cases
API POST request with quotes: POST /comment with body: {"text": "User said: \"Great job!\""}. User input: User said: "Great job!". Escape quotes: \" → valid JSON. Without escaping: {"text": "User said: "Great job!""} (syntax error).
Multiline error messages: API error: Validation failed: (newline) - Name required (newline) - Email invalid. JSON: {"error": "Validation failed:\n- Name required\n- Email invalid"}. Newlines → \n (JSON string format).
Config file with paths: Windows path: C:\Users\Admin\file.txt. JSON config: {"path": "C:\\Users\\Admin\\file.txt"}. Each backslash doubled (\\). Parser reads \\ as single \.
Debugging API responses: API returns: {"message": "Error:\nFile not found"}. Unescape: Error: (actual newline) File not found. Easier to read than \n in middle of text.
Embedding JSON in JSON: Store JSON as string: {"config": "{\"key\": \"value\"}"}. Inner JSON escaped: { → {, " → \". Parser reads: config = string "{\"key\": \"value\"}", parse again to get object.
Unicode in JSON: Product name: Café Münchën. JSON: {"name": "Café Münchën"} (UTF-8, valid). Or escaped: {"name": "Caf\u00E9 M\u00FCnch\u00EBn"} (ASCII-only, wider compatibility). Tool converts between both.
Examples
Common JSON escape/unescape scenarios.
Escape quotes
He said "Hello"
Escaped: He said \"Hello\"
JSON: {"message": "He said \"Hello\""}
Double quote (\"), backslash (\\). JSON strings delimited by ". Quote inside string must be escaped: \" (or string ends early). Backslash is escape char → must escape itself: \\.
Control characters
Newline: \n (U+000A). Carriage return: \r (U+000D). Tab: \t (U+0009). Backspace: \b (U+0008). Form feed: \f (U+000C). Must be escaped (can't use raw control chars in JSON strings).
/ can be escaped as \/ (optional). Reason: <\/script> in HTML (avoid closing script tag). JSON parsers accept both / and \/. Escaping not required (unlike \" and \\).
Not required escapes
Single quote (') doesn't need escaping in JSON (only " required). Spaces, letters, numbers: no escaping. Example: "Hello World" valid (no escaping needed). Only special chars/control chars escaped.
Escape in JSON vs JavaScript
JSON: only \" required for quotes (strings use double quotes). JavaScript: \" in double-quoted strings (""), \' in single-quoted (''). Template literals (`): no escaping quotes. Different rules.
Invalid escapes
\x (hex escape, not valid JSON). \0 (null, not valid JSON, use \u0000). \' (single quote, unnecessary). \v (vertical tab, not in JSON spec). Only listed escapes valid: \", \\, \/, \n, \r, \t, \b, \f, \uXXXX.
Single \ → double \\. Example: C:\Users → C:\\Users. Literal \n (backslash + n, not newline) → \\n (escaped backslash + n). Newline (actual) → \n (escape sequence).
Order of escaping
Escape backslashes first (prevent double escaping). Example: text has \n (literal backslash-n). 1) Escape \: \\n. 2) Don't escape n (already part of \\n). Wrong order: escape n to \n → escape \ → \\\n (incorrect).
Common mistakes to avoid
Not escaping quotes in JSON strings (syntax error)
Why it happens: {"message": "He said "Hi""} (unescaped quotes → string ends at 2nd ", "Hi"" is invalid syntax). Parser error: unexpected token after string.
How to avoid it: Escape quotes: {"message": "He said \"Hi\""}. Use tool: enter 'He said "Hi"' → copy escaped: He said \"Hi\" → insert in JSON string.
Using raw newlines in JSON strings
Why it happens: {"text": "Line 1 (actual newline) Line 2"} (raw newline breaks JSON syntax). JSON strings must be on single line (or use \n for newlines). Parser error: unterminated string.
How to avoid it: Escape newlines: {"text": "Line 1\nLine 2"}. Tool converts actual newline → \n (escape sequence). Parser reads \n as newline character (when used).
Single backslash in paths (C:\Users → invalid escape \U)
Why it happens: {"path": "C:\Users"} (\U not valid escape sequence). Parser error: invalid escape. Or misinterpreted: \t (tab), \n (newline) in C:\temp\new.
How to avoid it: Double backslashes: {"path": "C:\\Users\\"}. Tool: input C:\Users → escaped: C:\\Users. Each \ → \\. Parser reads \\ as single \.
Forgetting to unescape when displaying (shows \n instead of newline)
Why it happens: API response: {"error": "Error:\nDetails"}. Display as-is: Error:\nDetails (user sees \n text, not newline). Confusing (looks like error message has literal backslash-n).
How to avoid it: Unescape before displaying: Error:\nDetails → Error: (newline) Details. Use tool or parser (JSON.parse() auto-unescapes). User sees formatted message (newline = line break).
Why it happens: String: He said \"Hi\". Escape again: He said \\\"Hi\\\". Result: {"message": "He said \\\"Hi\\\""} (too many backslashes). Parser reads: He said \"Hi\" (not He said "Hi").
How to avoid it: Check if already escaped. If string has \" (escaped quote), don't escape again. Or unescape first → re-escape (if needed). Tool: paste → see if output looks correct.
Frequently asked questions
What's the difference between \n and \\n in JSON?
\n = newline character (escape sequence, becomes line break when parsed). \\n = literal backslash + n (two chars: \ and n, no line break). {"text": "\n"} → newline. {"text": "\\n"} → \n text.
Do I need to escape single quotes in JSON?
No. JSON strings use double quotes (""). Single quote (') doesn't need escaping. Example: {"text": "It's fine"} valid (no escaping needed). Only \" required for double quotes inside string.
How do I escape a backslash in JSON?
Single \ → double \\. Example: C:\Users → C:\\Users in JSON: {"path": "C:\\Users"}. Parser reads \\ as one \. Reason: \ is escape character (must escape itself).
Can JSON strings contain Unicode characters directly?
/ can be escaped as \/ (optional, not required). Reason: <\/script> in HTML (prevent closing script tag early). JSON allows both / and \/. Most tools don't escape / (unnecessary unless in HTML).
How do I fix 'invalid escape sequence' error?
Check escape: \x, \', \v invalid in JSON (not in spec). Valid: \", \\, \/, \n, \r, \t, \b, \f, \uXXXX. Example: \x41 → \u0041 (hex escape: use \u). Or literal: \\x41 (backslash-x-4-1).
Do I need to escape spaces, letters, numbers?
No. Only escape: special chars (", \, /), control chars (\n, \t, \r, \b, \f), non-ASCII (optional: Unicode). Spaces, letters (a-z), numbers (0-9): no escaping. Example: "Hello 123" valid as-is.