araç köşesi

JSON Escape / Unescape

Turn JSON or any text into a string literal you can paste into code, or unescape a string back into readable JSON

Your data stays with you. Conversion happens inside the browser; nothing is sent to a server.

How it works

There are two typical jobs. The first is putting JSON inside a string: when you need JSON in a unit test, a database column or a field of another JSON document, paste the JSON into the left pane and leave Escape selected. On the right you get a one-line string wrapped in double quotes, with a backslash before every inner quote and \n for every line break: {"name":"x"} → "{\"name\":\"x\"}". You can paste it straight into JavaScript, Java or C# code. The second job is the reverse: when a log line, an API response or an error message shows escaped JSON like "{\"name\":\"x\"}", paste it and choose Unescape. The outer quotes are dropped, the escapes are decoded, and if the result is valid JSON it comes back indented with 2 spaces. If the string was escaped twice (you see \\\"), the tool notices and decodes one more level. For SQL, single quotes are doubled (O'Brien → 'O''Brien'); for a CSV cell, double quotes are doubled. With Java / C#, every non-ASCII character is written as \u00e9 and so on, so it survives whatever encoding the source file is saved in.

This tool is also known as json escape, json unescape, json to string, string to json, json stringify online, json encode decode online.

What is Escape character?

An escape character removes the special meaning of the character that follows it; in JSON, JavaScript, Java and C# it is the backslash (\). Because a string is delimited by double quotes, a quote inside it is written as \" so the string does not end there, and the backslash itself becomes \\. Invisible characters are written with escapes as well: \n is a line break, \t a tab, and \u00e9 the code number of é.

What is String literal?

A string literal is text written between quotes inside source code or JSON: "Hello". The literal and the text it holds are not the same thing; the literal "5\" screen" holds the text 5" screen. This tool converts between the two: it builds a literal from text (escape) or extracts the text from a literal (unescape), with the quoting rules of the language you pick.

What is the difference between JSON escaping and URL encoding?

JSON escaping is for putting text safely inside a string literal: only quotes, backslashes and control characters change, while letters and spaces stay as they are. URL encoding is for making text part of a web address: a space becomes %20, é becomes %C3%A9, and everything outside plain ASCII is percent-encoded. To put JSON into a URL query parameter you need both, one after the other; to embed it in code or another JSON field, JSON escaping alone is enough. Base64 is a third thing again: it carries text in an unreadable form.

Which character becomes what

In a JSON or JavaScript string, a double quote would end the string, so it is written as \"; a backslash starts an escape, so it becomes \\. Invisible characters such as line breaks, tabs and carriage returns cannot sit raw inside the string and become \n, \t and \r. Other control characters are written as \u001f. U+2028 and U+2029 are escaped too, because older JavaScript engines treat them as line breaks inside a string and the code breaks.

The Java / C# target uses the same escapes and additionally writes every non-ASCII character as \uXXXX: é → \u00e9, ñ → \u00f1. That keeps accented letters intact in a .java file saved in a different encoding, and the output is still valid JSON. The SQL target only doubles single quotes; the CSV target only doubles double quotes and keeps line breaks inside the cell.

  • " → \" · \ → \\ · line break → \n · tab → \t
  • é → \u00e9 (Java / C# target only)
  • O'Brien → 'O''Brien' (SQL)
  • 5" screen → "5"" screen" (CSV cell)

Traps: double escaping and MySQL backslashes

When JSON is stored as a string inside another JSON and the whole thing is escaped again, quotes turn into \\\" — common in logs. On Unescape the tool decodes one level, and if the result is still a quoted JSON string it decodes another, telling you how many levels it removed. Valid JSON is then indented, unless it holds a number JSON.parse would change (1.0, or a 17-digit ID); in that case the text is left as is so no data is altered.

Standard SQL escapes a single quote by doubling it, and that is all the tool does. MySQL, in its default mode, also treats the backslash as an escape: a path like C:\new becomes a line break. If you use MySQL and the text contains backslashes, use a parameterized query instead of a hand-built string. For the same reason, escaping user input with this tool and gluing it into a query is not protection against SQL injection.

Frequently asked questions

How do I convert JSON to a string?

Paste the JSON into the left pane and keep Escape and JSON / JavaScript selected. The right pane shows a one-line string in double quotes, with inner quotes as \" and line breaks as \n. Paste that string into your code or into another JSON field as it is.

How do I turn an escaped JSON string back into normal JSON?

Paste the escaped string (like "{\"a\":1}") and choose Unescape. The outer quotes go away, \" becomes a quote and \n a line break. If the result is valid JSON, it is indented with 2 spaces; if the string was escaped twice, the tool detects it and decodes another level.

Why do accented letters show up as \u00e9?

With the Java / C# target, every non-ASCII character is written as \uXXXX, so it survives even if the source file is saved in another encoding. To keep letters like é or ü as they are, choose the JSON / JavaScript target.

Is the text I paste sent to a server?

No. Escaping and unescaping happen entirely in your browser, so even JSON with API keys, passwords or customer data never leaves this page. Once loaded, the page also works offline.