Escape JSON

JSON-escape a string for embedding inside another JSON value or code literal - with or without outer quotes, plus unescape. Free, offline, client-side, instant, secure.

Convert a raw string into its JSON-escaped form ("\", \\\, newlines → \n, control chars → \uXXXX). Three modes: escape with outer quotes, escape without, or reverse the process.

- paste text to begin

How to Use Escape JSON

  1. Pick a mode. "Escape - JSON string literal" wraps the output in "…" and escapes inner content - paste-ready as a JSON value. "Escape - bare" gives just the escaped characters with no outer quotes - useful when you're already inside a quoted string. "Unescape" reverses either form.
  2. Paste your text. Output updates live (100 ms debounce). Use any input - a whole JSON document, a code snippet, a log line, or text with quotes and newlines.
  3. Read the stats line. Mode label, input → output character counts, and how many escape sequences were emitted (escape mode) or decoded (unescape mode).
  4. Errors only happen in unescape mode when the input has a malformed escape (x, an unterminated uXXX, or a stray backslash). The stats line turns red with the parser's error message.
  5. Copy or download with the buttons. Ctrl/Cmd + Enter copies. Download writes escaped.json.txt (or unescaped.txt in unescape mode).

Frequently Asked Questions

What is JSON escaping and when do I need it?

JSON escaping converts a string so it can sit inside a JSON string value or be embedded as a code literal. The required escapes per RFC 8259 are: "", \, the C-style control characters b f n r t, and any other character below U+0020 as uXXXX. Use this tool when you have arbitrary text (a quote-containing message, a multi-line log, a source code snippet) and need to put it inside JSON or inside a JS/Python/etc. string literal.

What’s the difference between the two escape modes?

“With outer quotes” gives you a complete JSON string literal – paste it directly as a JSON value ("He said "hi""). “Bare” omits the surrounding quotes – useful when you’re already inside a quoted string (e.g. building a JavaScript template literal: "He said " + bareEscape + " loudly").

Does this validate that my input is valid JSON?

No – and it shouldn’t. The tool treats input as an arbitrary string and produces the escaped form regardless. That’s by design: you might be escaping a snippet of source code, a log entry, or a paragraph of text that isn’t JSON. For JSON validation, use the JSON validator/formatter tool.

How is this different from JSON.stringify?

It’s not – internally the escape modes use JSON.stringify(string), optionally stripping the outer quotes. JSON.stringify on a string does exactly the right thing per RFC 8259. The value the tool adds over typing that in the console is the modes, the live preview, the stats, copy/download, and the unescape direction.

Does unescape work with both quoted and unquoted input?

Yes. If the input starts and ends with ", the tool treats it as a complete JSON string literal and parses it directly. Otherwise it wraps the input in "…" internally before parsing. Either way you get back the decoded plain string.

What happens with control characters or Unicode?

Control characters (U+0000-U+001F) are escaped as b f n r t for the named ones and uXXXX for the rest. Non-ASCII characters (accented letters, emoji, CJK) are not escaped – they pass through verbatim, since JSON is required to be UTF-8 and any modern parser handles them. If you specifically need ASCII-only output, post-process with a Unicode-to-uXXXX converter.

Can I escape huge inputs?

Practically yes. The implementation is one JSON.stringify call – O(n) over the input length. A 1 MB string takes about 50 ms on a 2020 laptop. The 100 ms input debounce means you won’t see lag while typing even on large inputs.

Is my data secure?

Yes. The page loads three static files (HTML, CSS, JS) and then runs entirely in your browser. Your input never leaves the device – no fetch, no XHR, no analytics, no cookies. You can disconnect from the internet after the page loads and the tool still works.

Is this tool free?

Yes – free, unlimited, no signup, no watermark. Use the output anywhere. Attribution to is appreciated but not required.