JSON escape / unescape

Turn text into a JSON string literal (JSON.stringify) or decode a quoted JSON string.

{{ jsonStringEscape.message }}

Overview

When you embed text into a JSON value, certain characters must be escaped to avoid breaking the document structure. ECMA-404 defines which ones: double quotes must be preceded by a backslash, backslashes themselves are doubled, and control characters such as newline, carriage return, and tab get specific two-character sequences. Unicode characters outside the basic ASCII control range can be represented using four-digit hexadecimal notation.

The most common bug appears when building JSON manually by string concatenation. Everything works fine until a user types a double quote, a backslash, or an emoji outside the Unicode BMP. The string breaks and the parser rejects the entire document. The error may surface far from the origin when the JSON is nested across multiple layers or serialized inside another system.

The right approach is always to use the language serialization function: JSON.stringify for JavaScript and TypeScript, json_encode for PHP, json.dumps for Python, and JsonSerializer.Serialize for .NET. This tool applies exactly that logic: converts any text into a JSON string literal ready to embed in files or payloads, with no risk of breaking syntax.

The reverse direction, unescape, is useful when you receive a JSON literal serialized inside another JSON, the so-called double-encoded JSON. This pattern appears frequently in application logs and queue messages, when the logging layer serializes the entire object as a string rather than nesting it directly in the document.

Technical deep dive

Common questions summarized

  • What is this tool for?: It runs fully in your browser: useful to validate, format, or convert data in everyday development.
  • Are my inputs sent to a server?: Processing happens locally with JavaScript. We do not store what you paste into the text areas.
  • Can I use this for real production data?: Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.

Sample payload to try

  • See also the larger "Code Snippets" sample; paste this excerpt to try locally: Escape — linha1\n"aspas" → "linha1\\n\"aspas\""

Tool guide

  • What a JSON string is In JSON, text sits in double quotes; special characters use escapes like \n, \", \\.

  • What the tool does “Escape” mode turns plain text into the literal you would paste inside JSON. The reverse reads a quoted JSON string and returns the text.

  • Why use it Hand-build JSON files, fix payloads, and avoid syntax errors from newlines or quotes.

Code Snippets

Code example
linha1\n"aspas" → "linha1\\n\"aspas\""

Escape

linha1\n"aspas" → "linha1\\n\"aspas\""

FAQ

What is this tool for?

It runs fully in your browser: useful to validate, format, or convert data in everyday development.

Are my inputs sent to a server?

Processing happens locally with JavaScript. We do not store what you paste into the text areas.

Can I use this for real production data?

Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.