gizmobench

JSON Escape

Convert ordinary text into a JSON-safe string literal and inspect the exact escaped output. The operation runs locally and supports copy-ready output.

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 characters from the start of the box, beginning at 1.

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.

Common questions

What does JSON escaping change?
Quotes, backslashes and control characters are represented with JSON escape sequences so the value can be embedded safely in a string.

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.