JSON string escaper
Say "hello", a line break and world become Say \"hello\"\nworld: three escapes, ready to paste between double quotes without breaking the document around it. It also turns escaped text back into plain characters. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Text
- Say "hello" world
- Calculation mode
- Encode
- Result
- Say \"hello\"\nworld
- Encoding
- json_string
- Input length
- 17
- Output length
- 20
The path is fully deterministic: the same text and mode always produce the same result, with no network calls, no random salts, and no date-dependent shortcuts. Small checks include encoding a line that contains a quote and a newline into backslash-escaped form, and decoding a path that uses doubled backslashes back into real separators.
Why one quote mark can break a whole document
Inside a data document, a piece of text is wrapped in double quotes, and the first unescaped quote ends it. A quote that belongs to the text itself therefore has to be written with a backslash in front, the backslash has to be doubled because it is the escape marker, and control characters such as line breaks and tabs cannot appear raw at all. In the example, Say "hello", a line break and world need three escapes, two quotes and the line break, so 17 characters become 20. Paste the result between your quotes and the document stays intact.
Turning escapes back into text, and the slips it catches
Decoding does the reverse: it reads the usual short forms for quote, backslash, slash, backspace, form feed, line break, return and tab, plus the four-digit backslash u form, and gives you the real characters. A file path written with doubled backslashes comes back with single separators. If the text holds an incomplete sequence, a backslash pair that is not allowed, a bare quote or a raw control character, the tool stops with a message instead of letting the mistake slip through. The same text and option always give the same result.
FAQ
Which characters are escaped on encode?
Encode rewrites double quote, backslash, backspace, form feed, newline, carriage return, tab, and any other control in U+0000–U+001F as \uXXXX. Other characters are left unchanged.
Is the result deterministic?
Yes. The same text and mode always produce the same result with no network, randomness, or date-dependent behavior.
Does the tool add the outer double quotes?
No. It returns only the content that goes between the quotes, so the opening and closing quotes of your document stay as they are. When decoding, paste only what sits inside them as well.
How is a line break written inside the quotes?
As a backslash followed by n. A tab becomes backslash t and a carriage return backslash r, while control characters without a short form are written as backslash u followed by four hexadecimal digits.
Why does decoding refuse my text?
Because it holds something that cannot appear in a valid escaped string: an incomplete sequence, a backslash followed by a letter that is not allowed, a bare double quote or a raw control character. The tool stops and says so instead of guessing.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/enc/json-string-escape \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"Say \"hello\"\\n"}'const res = await fetch("https://api.kit.forhosting.com/enc/json-string-escape", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"text": "Say \"hello\"\\n"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/enc/json-string-escape",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"text": "Say \"hello\"\\n"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/enc/json-string-escape", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"text":"Say \\"hello\\"\\\\n"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"text":"Say \"hello\"\\n"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/enc/json-string-escape", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"text": "Say \"hello\"\\n"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "enc.json_string_escape",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
This JSON string escaper converts plain text into the escaped form required inside a JSON string value, and it reverses the same mapping when you paste escaped content back into ordinary characters. Encoding rewrites double quotes, backslashes, and control characters so a hand-built payload, template, or log line can sit safely between JSON quotes without breaking the surrounding document. Decoding accepts the standard JSON escapes—quote, backslash, optional slash, the short forms for backspace form-feed newline return and tab, and four-digit u-escapes—and it fails loudly on incomplete sequences, illegal backslash pairs, raw double quotes inside the content, or bare control characters so typos never silently survive into production.
What JSON string escaping is and what this tool returns
A literal double quote must appear as a backslash-quote pair, a literal backslash must be doubled, and every control character in the U-plus-zero-zero-zero-zero through U-plus-zero-zero-one-F range must be written as a short escape when one exists or as a four-digit u-escape otherwise. A JSON string value is delimited by double quotes, and the characters that may appear between those quotes are constrained by ECMA-404 and the common JSON.stringify rules used across languages. This page implements that encode set on the encode path and the reverse on decode: the response is the string content only, without adding or removing the outer quotes of a full JSON document. The JSON response always includes result for the transformed string, mode echoing encode or decode, encoding fixed to json_string, and input_length plus output_length so tests can assert sizes. Encode also reports escapes_applied and decode reports escapes_resolved so you can confirm how many special characters or escape sequences were rewritten. There is no partial silent skip for a broken sequence: either every backslash pair is legal JSON or the request fails with invalid_input.
How text and mode are read and how results stay reproducible
Decode scans for backslash-led sequences: quote, backslash, slash, the five short control forms, and u followed by exactly four hexadecimal digits. The preferred payload field is text, with aliases input, value, s, and payload so forms, query strings, and SDK clients can reuse the same contract without renaming columns. Mode defaults to encode and accepts decode explicitly; aliases op, direction, and action map to the same switch for scripts that already use those names, and escape or unescape are accepted as synonyms. Encode walks the string by UTF-16 code units and replaces only the characters that JSON requires to be escaped, leaving letters, digits, and ordinary Unicode unchanged so readable copy stays readable. Because backslash is rewritten in the same left-to-right pass as quotes and controls, you get a single consistent escaping pass that matches the character rules of JSON.stringify for string content. An incomplete trailing backslash, a short escape that is not in the JSON set, a u-escape without four hex digits, a raw double quote, or a bare control character raises invalid_input with a message that names the problem. The length ceiling of one hundred thousand characters keeps Worker memory predictable while still covering templates, sample payloads, and most paste buffers. Pair the free browser run on this page with the priced API when you need the identical mapping inside an automated pipeline without re-implementing JSON string tables yourself. Invalid inputs return invalid_input and are not charged, which keeps validation cheap while successful transforms remain a fixed item price at $0.002.
Where JSON string escape and unescape fit in developer workflows
Pipeline authors decode entity-heavy or escape-heavy exports from legacy systems so application code works with true newlines and quotes instead of literal backslash-n sequences. Frontend and backend teams encode dynamic titles and labels before placing them inside a quoted JSON field so a single quote, backslash, or newline cannot break the surrounding document. Quality engineers generate deterministic encode and decode pairs for contract tests so a middleware that claims JSON string support cannot silently switch to a non-standard escape table between releases. Educators use the same tool when teaching the difference between a full JSON document, a JSON string value, and the small set of escapes that the specification allows inside that value. On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split—free interactive exploration and a priced, identical API—matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the escaped result. Pair it with URL percent-encoding or XML entity helpers when you need broader text transforms, and with other encoding endpoints when you are building a small lab of free, deterministic tools for CI and documentation.
Integration use cases
Safe JSON field content
Escape titles, messages, and user snippets so quotes, backslashes, and newlines cannot break a hand-built or templated JSON string value.
Fixture and log cleanup
Decode JSON string escapes from logs, exports, or golden files back into plain Unicode for readable diffs and application code.
Deterministic CI pairs
Generate reproducible encode and decode pairs for unit tests, contract checks, and middleware that must match JSON.stringify string rules.
Technical questions
What does the JSON string escaper cost?
It is free in your browser on this page. Through the API a successful request costs $0.002; invalid inputs are not charged.
What modes are supported?
mode=encode (default) turns plain text into JSON string escapes. mode=decode turns those escapes back into characters.
What happens if an escape is incomplete or illegal?
Decode fails with invalid_input. Lone backslashes, non-JSON escape letters, bad \u forms, raw quotes, and bare controls are rejected.