JSON Escape/Unescape

Escape special characters in JSON strings or unescape them back to normal text.

What is JSON Escaping? JSON escaping converts special characters into escape sequences so they can be safely used within JSON string values. This enables embedding stringified JSON objects as string values within other JSON objects, preventing parsing errors and ensuring your JSON structure remains valid.

Reserved Characters: The following characters are reserved in JSON and must be escaped:

  • \b - Backspace
  • \f - Form feed
  • \n - Newline
  • \r - Carriage return
  • \t - Tab
  • \" - Double quote
  • \\ - Backslash

Use cases: Preparing strings for JSON serialization, sanitizing user input before storing in JSON, fixing malformed JSON strings, and ensuring safe transmission of text data through JSON APIs.

Example: Embedding stringified JSON

Original JSON object:
{
  "name": "John",
  "age": 30
}

After stringifying (to embed as a string):
{"name":"John","age":30}

After escaping (safe to embed):
{\"name\":\"John\",\"age\":30}

Embedded in another JSON object:
{
  "userId": 123,
  "metadata": "{\"name\":\"John\",\"age\":30}"
}