Skip to content

Escape Text

Escape a string for JSON, JavaScript, SQL, shell or regex.

Quick Tool Overview

Escape Text escapes a string for the format you name — JSON, JavaScript, HTML, SQL, shell, CSV, regex or URL — following that format's own rules rather than a generic approximation, so the result is genuinely valid in that context.

What it does
Escapes text for a specific code or data format
You give it
A string and the format it is going into
You get back
The correctly escaped literal
Best for
Hand-building literals for code, config and queries
Text Tools Free, unlimited use No sign-up Runs in your browser

About the Escape Text

Every format has characters it treats specially, and putting one in a string without escaping it is how injection bugs and syntax errors both happen. A quote inside a JSON string, a backslash inside a regular expression, a semicolon inside a shell argument — each needs its own escape, and each format\'s rules are different.

This escapes text for the format you choose, following that format's actual rules rather than a generic approximation. JSON escapes quotes, backslashes and control characters as the specification requires. SQL doubles single quotes. Shell single-quotes the whole string and handles embedded quotes correctly. Regex escapes every metacharacter. CSV doubles quotes and wraps fields containing delimiters. The result is safe to paste into that context.

Key features of the Escape Text

Eight real formats

Each with its own rules — SQL doubles quotes, regex escapes metacharacters, shell wraps and requotes.

Control characters handled

JSON and JavaScript get \n, \t and \uXXXX forms, as their specifications require.

Wrapping quotes included

Where a format needs the string quoted, the quotes are part of the output rather than left to you.

CSV field rules

Quotes doubled and the field wrapped only when it contains a delimiter, quote or newline.

Says what it is not for

The page states plainly that parameterised queries, not escaping, are the answer to SQL injection.

How to use the Escape Text

  1. 1

    Paste your text

    The string that needs to go into code, a query or a config file.

  2. 2

    Choose the target format

    JSON, JavaScript, HTML, SQL, shell, CSV, regex or URL.

  3. 3

    Read the escaped result

    Each format's own rules are applied, including any required wrapping quotes.

  4. 4

    Paste it into place

    The result is valid for the context you selected.

Frequently asked questions

No. Use parameterised queries — they are the only reliable defence, because escaping depends on knowing the exact database, character set and context. This tool is for building a literal by hand, not for handling user input in an application.

Reviews of the Escape Text

What people who use the Escape Text think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the Escape Text. It takes half a minute and no account.

Write the first review

More text tools