DevPik Logo

JSON Escape

Escape quotes, backslashes, newlines, tabs, and Unicode control characters so raw text becomes a valid JSON string value — perfect for embedding SQL queries, HTML, or logs inside JSON payloads.

Why Use JSON Escape?

Embed a multi-line SQL query, a JWT, or an HTML snippet inside a JSON payload and you'll hit the quote-escape problem immediately — a single unescaped `"` breaks the entire file. Hand-escaping with sed works but is easy to get wrong for control characters and Unicode. This tool round-trips anything you paste — source code, shell commands, PEM-encoded keys, emoji-laden copy — into a valid JSON string value in one keystroke. Useful when building test fixtures, writing Postman examples, or embedding error messages in log payloads that must stay JSON-parseable.

How to Use JSON Escape

  1. Paste or type your raw text or JSON string into the input panel on the left.
  2. The tool instantly escapes all special characters — double quotes, backslashes, newlines, tabs, and Unicode control characters — in real time.
  3. Copy the escaped output from the right panel, or click the Swap button to switch to JSON Unescape mode.
  4. Use this when embedding raw text (SQL queries, HTML, log lines) inside a JSON string value — the unescaped form would break the JSON.
  5. Click Swap to flip directly into JSON Unescape mode if you pasted output that's already escaped and need to see the original.

Worked Examples

Escape a SQL query for a JSON payload

Input
SELECT * FROM users WHERE name = "Jane"\nAND active = true;
Output
SELECT * FROM users WHERE name = \"Jane\"\\nAND active = true;

Double quotes and newlines both need escaping before embedding in JSON.

Escape a Windows file path

Input
C:\Users\jane\docs\report.pdf
Output
C:\\Users\\jane\\docs\\report.pdf

Every backslash doubles — forget this and the JSON parse will fail with "invalid escape".

Escape UTF-8 text for a legacy ASCII-only system

Input
café
Output
caf\u00e9

Optional — JSON allows raw UTF-8, but older tools prefer Unicode-escaped output.

About JSON Escape

JSON Escape is a free online tool that converts special characters in your text into their JSON-safe escape sequences. When building JSON strings manually or embedding text inside JSON payloads, characters like double quotes ("), backslashes (\), newlines, tabs, and control characters must be properly escaped to produce valid JSON. This tool handles all JSON escape characters defined in the RFC 8259 specification, including \" for double quotes, \\ for backslashes, \n for newlines, \t for tabs, \r for carriage returns, \b for backspace, \f for form feed, and \uXXXX for Unicode control characters. Everything runs 100% client-side in your browser — your data is never sent to any server. Developers, API engineers, and anyone working with JSON data use this tool to quickly escape JSON strings for embedding in code, API requests, configuration files, and database queries.

Troubleshooting & Common Issues

JSON.parse throws "Unexpected token" after escaping

Make sure you escaped only the *contents* of the string value, not the surrounding quotes. Wrap the escaped output in double quotes, then embed that into the parent JSON. Also check for unescaped control characters — tabs (0x09) and newlines must become `\t` and `\n`.

Output looks like it has too many backslashes

One level of escaping is correct for a JSON string value. If you're also pasting the result into a shell script or a language that uses backslash escapes, you'll need a second round — but that's a shell/language concern, not a JSON one.

Forward slashes `/` became `\/`

Escaping `/` is optional per RFC 8259 — some tools do it for HTML-safety when embedding JSON inside `<script>` tags. Disable "escape forward slash" in the options if your downstream parser is strict about unnecessary escapes.

Frequently Asked Questions

What characters need to be escaped in JSON?

According to the JSON specification (RFC 8259), you must escape double quotes (\"), backslashes (\\), and all control characters (U+0000 through U+001F). This includes newlines (\n), tabs (\t), carriage returns (\r), backspace (\b), and form feed (\f). Forward slashes (/) may optionally be escaped as \/ but this is not required.

How do I escape double quotes in JSON?

To escape a double quote inside a JSON string, prefix it with a backslash: \". For example, the text He said "hello" becomes He said \"hello\" when properly escaped for use inside a JSON string value.

Does JSON need to be escaped?

Yes — any string value inside JSON that contains special characters must have those characters escaped. If you don't escape characters like quotes or backslashes, the JSON will be invalid and parsers like JSON.parse() will throw a syntax error. This tool automates the escaping process so you don't have to do it manually.

What is the difference between JSON escape and JSON unescape?

JSON escape converts raw text into a JSON-safe format by adding backslash escape sequences before special characters. JSON unescape does the reverse — it converts escaped sequences back into their original characters. Use escape when preparing text for JSON, and unescape when reading escaped JSON string data.

How do I escape a backslash in JSON?

A single backslash (\) in JSON must be escaped as a double backslash (\\). This is because the backslash is the escape character itself in JSON, so it needs to be escaped to be treated as a literal backslash.

Is my data safe when using this tool?

Absolutely. This JSON escape tool runs entirely in your browser using client-side JavaScript. Your text is never transmitted to any server, ensuring complete privacy and data security.

Related Tools

Was this tool helpful?