Escape / Unescape JSON

Escape JSON for string usage or unescape back to JSON

Loading editor...
Loading editor...

JSON String Escape & Unescape Tool

Understanding the Basics

JSON strings must follow strict escaping rules defined in RFC 8259. Certain characters cannot appear literally inside a JSON string and must be represented as escape sequences: double quotes become \", backslashes become \\, newlines become \n, carriage returns become \r, tabs become \t, and form feeds become \f. Additionally, any Unicode control character (U+0000 through U+001F) must be escaped as \uXXXX. This escaping becomes critical when you need to store a JSON document inside another JSON string — for example, embedding an API response payload as a string value inside a logging record, or storing a JSON template inside a database column that serializes data as JSON. Forgetting to escape nested JSON causes the outer JSON parser to see unmatched quotes and brackets, producing invalid JSON errors that are notoriously confusing to debug. The reverse operation — unescaping — recovers the original characters from an escaped string, which is necessary when extracting embedded payloads from log lines or database records. Our tool handles both directions, correctly processing all RFC 8259 escape sequences.

How to Use the Tool

  1. Select the operation mode: "Escape" (raw text → JSON-safe string) or "Unescape" (JSON string → raw text).
  2. Paste your content into the input editor.
  3. The output appears instantly in the right panel with all escape sequences applied or reversed.
  4. Click the Swap button (⇄) to reverse the direction and process the output as the new input.
  5. Use Copy to grab the escaped/unescaped result for embedding in your code or logs.

Key Features & Specifications

  • Bidirectional: escape raw text to JSON-safe strings and unescape JSON strings back to raw text
  • Handles all RFC 8259 escape sequences: \", \\, \n, \r, \t, \f, \b, \uXXXX
  • Correctly processes Unicode escape sequences including surrogate pairs
  • Swap button reverses input and output with one click for quick round-trip testing
  • Preserves all non-escaped characters exactly as-is

Frequently Asked Questions (FAQ)

Q:When would I need to escape JSON?
Common scenarios: storing a JSON payload inside another JSON string field (double-encoded JSON), embedding JSON in HTML data attributes, inserting JSON into SQL string columns, and transmitting JSON through systems that process backslashes specially (like shell scripts).
Q:What is the difference between escaping and encoding?
Escaping replaces characters with alternative representations that are safe in a given context (e.g., \n for newline in JSON). Encoding transforms the entire binary representation (e.g., Base64 encodes bytes as ASCII characters). For JSON strings, you escape; for binary data embedded in JSON, you encode then escape.
Q:My unescaped output contains \u0000 — what is that?
That is the null character (Unicode code point 0). Some JSON producers emit \u0000 to represent an explicit null byte within a string. It is rarely valid in text strings and may cause issues in null-terminated C string handling. Treat it carefully.