Escape / Unescape
Escape to HTML entities or JSON strings, or unescape back.

Escape / Unescape Tool — HTML Entities & JSON String Escaping

This tool converts text to HTML entities or JSON-safe escaped strings, and reverses the process too. It's built for developers who need to escape HTML special characters before embedding user-generated text in a web page, or who need to properly escape a string for safe inclusion in a JSON payload. Paste your text, choose a direction, and get correctly escaped or unescaped output instantly.

⚡ Key Takeaways

  • Escapes text to HTML entities or JSON-safe strings, and reverses either process.
  • HTML escaping and JSON escaping are not interchangeable — match the type to the context.
  • Prevents user-generated text from being misread as live HTML markup.
  • Essential when hand-building a JSON string containing quotes or line breaks.

What, Who, When & Why

What it's forEscapes text to HTML entities or JSON-safe strings, and reverses the process.
Who it's forDevelopers who need to safely display user-generated text in HTML, or embed a string inside a JSON payload.
When to use itBefore rendering untrusted or special-character text in a web page, or hand-building a JSON string with quotes or line breaks.
Why it's neededUnescaped special characters can break HTML rendering or JSON parsing, and in some cases create real security issues.
Best way to use itAlways match the escaping type to where the text will actually be used — HTML escaping doesn't make text safe for JSON, and vice versa.

How to Use Escape / Unescape

  1. Paste your text into the Input box.
  2. Click Escape HTML to convert special characters (like <, >, &) into their HTML entity equivalents.
  3. Or click Escape JSON to escape characters that need special handling inside a JSON string (like quotes and newlines).
  4. Use the corresponding Unescape buttons to reverse either process.

Example

The literal text <div>Hello & welcome</div> (an actual HTML snippet, typed as plain characters) becomes, after HTML escaping, a version where each <, >, and & is replaced with its entity code — so it can be safely displayed as visible text on a web page rather than being interpreted as an actual HTML tag by the browser. This is exactly the transformation needed when displaying code snippets or user-submitted HTML as readable text instead of rendering it.

Key Features

  • HTML escaping — converts characters like <, >, &, and quotes into safe HTML entities.
  • HTML unescaping — converts HTML entities back into their original characters.
  • JSON escaping — escapes quotes, backslashes, and control characters for safe inclusion in a JSON string.
  • JSON unescaping — reverses JSON escaping back to the original text.

Practical Use Cases

  • Displaying user input safely: escape text before rendering it in HTML to prevent it from being interpreted as markup, which also helps prevent certain injection issues.
  • Building JSON payloads by hand: properly escape a string containing quotes or line breaks before inserting it into JSON.
  • Debugging encoded text: unescape HTML entities or JSON escape sequences to read the original content when reviewing logs or API responses.
  • Preparing code snippets: escape HTML so example code displays correctly on a web page instead of rendering as live markup.
  • Documentation: safely show raw HTML or JSON examples within a webpage without them being executed or malformed.

Tips for Best Results

  • Always match the escaping type to the actual context the text will be used in — HTML escaping doesn't make text safe for JSON, and vice versa.
  • When debugging an API response with escaped characters, use Unescape to read the original text before troubleshooting further.
  • For displaying code examples on a webpage, HTML-escape the code first so tags like <script> show as visible text instead of executing.

Related Terminology

HTML entities are special codes (like &lt; for <) used to display characters that would otherwise be interpreted as HTML markup. JSON escaping uses backslash sequences (like " for a quote or for a newline) so special characters can be safely included inside a JSON string value. Both are forms of "encoding for context" — making text safe to include within a specific format without changing its underlying meaning.

Important Considerations

HTML escaping and JSON escaping serve different purposes and use different character sets — escaping for one context doesn't make text safe for the other. Always match the escaping type to where the text will actually be used, since using the wrong type of escaping can leave your text vulnerable to display issues or, in more serious cases, security problems if untrusted text is inserted without the correct escaping.

Related Tools

If you're preparing data for an API request body, the CSV ⇄ JSON Converter can help build the underlying JSON structure. For sanitizing SQL text instead, see the Query Sanitizer. To clean up whitespace in text before escaping it, use the Whitespace Trimmer.

Frequently Asked Questions

How do I escape HTML special characters?

Paste your text into the Input box and click Escape HTML — characters like <, >, and & are converted into their safe HTML entity equivalents.

What's the difference between HTML escaping and JSON escaping?

HTML escaping converts characters that have special meaning in HTML markup, while JSON escaping converts characters (like quotes and newlines) that have special meaning within a JSON string value — they're used in different contexts and aren't interchangeable.

Can I reverse the escaping to get my original text back?

Yes, use the corresponding Unescape option to convert escaped HTML entities or JSON sequences back into the original characters.

Why does it matter which type of escaping I use?

Using the wrong type of escaping can leave your text displaying incorrectly, or in more serious cases, create a security issue if untrusted text isn't properly escaped for the context it's placed in.