Developer

JSON String Escaping: What Needs Escaping and When

When you manually construct JSON strings, special characters like quotes and newlines can break the structure. Which characters must be escaped inside a JSON string, when you need to do it, and how it differs from URL encoding. Applying these recommended techniques ensures high visual quality, faster page load speeds, and reliable.

Awais 2 min readPublished
JSON String Escaping: What Needs Escaping and When

When you manually construct JSON strings, special characters like quotes and newlines can break the structure. This guide explains how to escape plain text into JSON-safe form and how to reverse escaped JSON back into the original text, using the ToolOrbit JSON Escape/Unescape tool.

What needs escaping in JSON

  • Double quotes must become \" inside a JSON string.
  • Backslashes become \\.
  • Newlines become \n, tabs become \t.
  • Non-printable characters are encoded as \uXXXX.
Hello "world"
Line two
->
"Hello "world"
Line two"

When to escape text

  • Embedding user input in a JSON payload.
  • Creating JSON strings inside JavaScript code.
  • Preparing API requests with dynamic fields.
  • Debugging JSON stored in config files or logs.

Using the tool

Paste raw text and choose Escape to get a JSON-safe string, or paste escaped JSON and choose Unescape to recover the original text. This is useful for fixing broken JSON fragments or preparing test data for APIs.

Note: The escaped output is a JSON string, not a full JSON document. If you need a full object or array, embed that string as a value inside your JSON structure.

Escaping vs URL encoding

JSON escaping makes a string safe *inside* a JSON document range: it produces the sequence of characters that, when parsed, yields your original text. URL (percent) encoding is a different grammar for a different container — query strings. The two are not interchangeable: a string escaped for JSON placed in a URL still breaks the URL, and vice versa. Keep the tool matched to the destination.

Real situations that need it

  • Injecting a user’s free-text answer into a payload your API sends further down.
  • Writing JSON snippets into a log line so the log stays parseable.
  • Copying a multi-line error message into a unit-test fixture.
  • Debugging a response where a raw quote broke the syntax before serialization.
The Unescape direction is the sharper tool for debugging: paste an escaped value and recover the human-readable original with its line breaks intact.

Escape pitfalls that are worth memorizing

The classic escape bugs are all symmetric: a quote unescaped halfway through a string, the backslash that half-escapes (“\n” producing a literal backslash-n), and control characters smuggling through as literal newlines. The fastest habit: escape once, and let the tool’s unescape direction show you what the parser will actually receive — if the round-trip does not come back exactly as you typed it, you found the leak.

  • Never hand-escape: build in the tool, then paste.
  • For API payloads, escaping an entire string once beats escaping each field separately.
  • Emoji and CJK pass through JSON unescaped by default — only quoting and control chars need the treatment.

Tools mentioned

More reading

View all guides
Free Developer Tools Online: 2026 Developer Toolkit & Guides
Developer

Free Developer Tools Online: 2026 Developer Toolkit & Guides

Explore 30+ free browser-based developer tools: JSON formatters, Base64 converters, cron generators, regex testers, SQL formatters, and hash generators.

3 min readPublished
CSS Border Radius: 15 Copy-Paste Examples
Developer

CSS Border Radius: 15 Copy-Paste Examples

15 modern CSS border radius examples: rounded cards, pills, circle avatars, asymmetrical organic blobs, and fancy 8-value border radius shapes.

3 min readPublished
Percent Encoding Reference Table (Every Character)
Developer

Percent Encoding Reference Table (Every Character)

Complete percent encoding ASCII reference table: quick lookup for spaces, slashes, ampersands, punctuation, and UTF-8 special characters in URLs.

3 min readPublished
URL Encoding Explained: %20 vs +, Reserved Characters & Rules
Developer

URL Encoding Explained: %20 vs +, Reserved Characters & Rules

Complete guide to percent encoding in URLs: learn when to use %20 vs +, how reserved characters like & and ? work, and how to avoid encoding bugs.

3 min readPublished
Cron Every Hour, Day & Midnight: All Daily Schedules
Developer

Cron Every Hour, Day & Midnight: All Daily Schedules

Master standard daily cron schedules: cron every hour, every day at midnight, twice a day, and custom hourly intervals with copy-paste examples.

4 min readPublished
Cron Expression Cheat Sheet — Copy-Paste Schedule Examples
Developer

Cron Expression Cheat Sheet — Copy-Paste Schedule Examples

Free cron expression cheat sheet with copy-paste examples for every 5 minutes, hourly, daily at midnight, weekdays only, and more.

5 min readPublished
Cron Every 10 Minutes — Syntax, Examples and Best Practices
Developer

Cron Every 10 Minutes — Syntax, Examples and Best Practices

Use the cron expression */10 * * * * to run jobs every 10 minutes, plus examples for common schedules and troubleshooting tips.

3 min readPublished
Why CSV Is Tricky to Parse: Delimiters, Quotes and Headers
Developer

Why CSV Is Tricky to Parse: Delimiters, Quotes and Headers

Why CSV files are harder to read correctly than they look, how to choose the right JSON shape, and the mistakes to avoid.

2 min readPublished