Escape text for safe embedding in JSON strings

Escape text for insertion inside a JSON string value.

freeworks offlinenothing uploaded
ToolJSON Escape
Input
Output

How it works

Quotation marks, reverse solidus, and control characters are represented with string escape sequences inside a quoted value; other Unicode characters may remain literal UTF-8. The escaped text is then part of a JSON string token, not a standalone JavaScript expression.

  • JSON keeps UTF-8 by default and reserves escapes for syntax and control characters.

Worked example

Escape for JSON
Escape special characters for safe embedding in a JSON string
Input
											Line 1
Line 2	"quoted"
										
Output
												Line 1\nLine 2\t\"quoted\"
											

When to use this

API payloads, newline-containing logs, and parser fixtures escape JSON strings.

Edge cases

  • An unescaped quote terminates the JSON string.
  • A raw control character below U+0020 is invalid JSON.
  • Escaping for JSON does not protect an enclosing HTML script context.

References