gizmobench
BrowseDaily

JSON Escape

Turn plain text into one JSON string literal with its outer double quotes included. Quotes and backslashes are escaped, and line breaks and tabs become \n and \t. Apostrophes, forward slashes, ampersands and ordinary Unicode stay readable because JSON does not require them to be escaped. Use Omitted if another serializer will add the outer quotes. This output is JSON text; embedding it in HTML or JavaScript requires the destination’s rules.

Direction
Quotes
Length
44 characters
Valid
Yes

Escaping the text into one JSON string literal, surrounding quotes included, so the result can be pasted straight into a JSON document.

  • Quote and backslashboth are escaped
    "He said \"hi\" about C:\\tmp"
  • Tab and line breakwritten \t and \n
    "Tab:\tdone\nNext line"
  • An unterminated literalnothing closes the quote
    The literal that opens at position 1 is never closed: the text ends at position 5 with no closing double quote. Add a closing double quote, or set Quotes to Omitted if the text never had them.

Type in either box: editing the text side escapes, editing the literal side unescapes, and the conversion runs once either way. Length counts the characters of the converted side. Positions in a refusal count UTF-16 units from the start of the box, beginning at 1; an emoji can occupy two positions.

Included or Omitted, and why it changes the answer. Included means the surrounding double quotes are part of the literal: it is what you have when you copy a value out of a JSON file, and it is what you want when you are about to paste the result back into one. Omitted means the inside of the literal on its own, which is what a log line, a stack trace or a shell variable usually hands you. Unescaping with the quotes Omitted refuses a raw double quote, because a literal cannot hold one, and unescaping with them Included refuses anything after the closing quote, because this reads exactly one literal.
Accuracy. Exact conversion by the JSON string rules, so what comes out parses as one string literal and reading it back returns the text you started with. Unescaping takes exactly one valid literal and names the position where an invalid one stops.

JSON string escape reference

The optional surrounding double quotes are separate from the string body. This is JSON encoding, not HTML or shell escaping.

CharacterJSON string body
Double quote\"
Backslash\\
Line feed\n
Tab\t
Carriage return\r
Backspace\b
Form feed\f
NUL\u0000
Forward slash/ (\/ is also accepted)
Apostrophe' (no escape required)
Ampersand& (no escape required)
Letter éé (\u00e9 is also accepted)

Common questions

Which characters does this JSON encoder escape?
Double quotes and backslashes must be escaped, along with controls below U+0020. Named escapes are \b, \t, \n, \f and \r; other controls and unpaired UTF-16 surrogates are written as \uXXXX. Ordinary é, 日本語 and emoji remain as Unicode text. A forward slash, apostrophe, ampersand, comma, colon and braces need no escape inside a JSON string. The reader also accepts the optional escaped forward slash \/. Escaping a lone surrogate makes the literal well-formed JSON text; decoding it can still produce that same lone surrogate.
Should I escape a single quote or forward slash?
Neither needs an escape in a JSON string. A single quote is left as an apostrophe, not written as an invalid backslash-apostrophe escape. A slash stays /, although \/ is accepted when decoding.
How do I escape a newline or Windows path?
Paste the actual newline or path into Text. Newlines become \n, and each backslash becomes a doubled backslash. The tool does one pass and warns when text already looks like an escaped JSON literal.
Can I put the result directly into HTML?
No. This encoder leaves <, > and & unchanged, and it does not neutralise a closing script tag. JSON string rules are separate from HTML text, HTML attributes, JavaScript source and SQL quoting. Store JSON as JSON, and use the target environment’s serializer or escaping rules when embedding it elsewhere. HTML entity conversion is a different job.
Does this page overwrite my saved direction and quote choice?
The Escape and Included presets apply while this page is open. Each preset value is saved only after you edit that control; other remembered settings still restore. Text is never stored.

Exact conversion by the JSON string rules, so what comes out parses as one string literal and reading it back returns the text you started with. Unescaping takes exactly one valid literal and names the position where an invalid one stops.