Before · webhook JSON
{"event":"payment.failed","message":"Card declined"}Escape JSON into a safe string for logs, APIs, config files, and language literals.
2× escapes one additional string layer. A quote may show three backslashes; forward slashes stay unchanged.
A practical guide to JSON strings
Use this free online JSON escape tool when a JSON document has to travel as text inside another value. Escape quotes, backslashes, tabs, and line breaks, choose one or two layers, then copy a result you can inspect before it reaches an API fixture, webhook log, or nested payload.
Before and after: a webhook handoff
Imagine a developer saving a provider's webhook body inside a test event. As a stand-alone JSON document, the event is already valid. But when the entire document becomes the value of a parent field named payload, its quotation marks are now characters inside another string. Those inner quotes and line breaks need escaping. If that parent is then stored as text one more time, the team needs a second pass. Seeing the nesting as separate steps is easier than adding backslashes by hand.
{"event":"payment.failed","message":"Card declined"}{\"event\":\"payment.failed\",\"message\":\"Card declined\"}{\\\"event\\\":\\\"payment.failed\\\",\\\"message\\\":\\\"Card declined\\\"}Use one pass for one wrapper. Choose two passes only when the already escaped text will itself be serialized as a string again. The 1× and 2× buttons run that exact number of passes directly; they do not depend on clicking the same button twice.
The rule behind the slashes
JSON strings use double quotes as boundaries, and a backslash introduces an escape sequence. Inside a string, the quotation mark, reverse solidus (backslash), and control characters from U+0000 through U+001F must be escaped. Common readable forms include \" for a quote, \\ for a backslash, \n for a line feed, \r for a carriage return, and \t for a tab. Other control characters can use a Unicode form such as \u0001.
A forward slash is not the same as a backslash. JSON allows \/, but does not require that form, so an address like https://api.example.com stays readable here. The rules are described in section 7 of RFC 8259.
Choose the layer
Turns a JSON document into string contents for one enclosing string. For example, a parent JSON object can store the child document in a payload field.
Escapes the first result one more time. Use it only when another string-serialization layer will process that value. Before an escaped quote, three visible backslashes can be correct: the quote and the two escape layers are all represented.
Those backslashes are not extra forward slashes in a URL. This tool leaves / characters unchanged.
A short working routine
The fastest reliable workflow is to identify the destination first. A valid JSON document can be formatted or minified here; ordinary text can also be escaped as text when that is what the receiving field expects.
Enter a valid JSON object, array, or a text value that needs to become JSON string content. The status above the editor reports whether the source parses as JSON.
Ask whether the receiving field wants a JSON object or a string containing JSON text. For a normal API request body, keep the object as JSON. Escape only when a field expects text.
Click the matching action once. Use 2× only for a second serialization layer. The output reports its level and character count so you can keep track of what you copied.
Format or minify valid JSON when useful, then copy or download. Test the result by placing it in the intended parent field and parsing that parent with the receiving stack.
A real payload workflow
Say a webhook provider sends {"event":"payment.failed","message":"Card declined"} and your test harness stores the raw body in a field called payload. Pasting the source here and choosing Escape 1× produces the inner characters for that field. The parent object can then contain a value like {"payload":"{\"event\":\"payment.failed\",\"message\":\"Card declined\"}"}. The parent's quotes still mark the outer string; the backslashes tell its parser that the child quotes belong to the payload text.
A second service might serialize that whole fixture into another string for a snapshot or log transport. That is the case for Escape 2×. After each boundary, decode exactly one layer before parsing the next JSON document. If you are not sure how many wrappers exist, inspect the schema or log the value at each handoff rather than adding more slashes until the error disappears.
For an ordinary HTTP request with Content-Type: application/json, the server usually expects the object itself. Pre-escaping the full request body changes the top-level value into text, which may cause a schema mismatch. Escape only the field that is defined to contain serialized JSON.
Keep a complete example response in a string property when a test runner, queue event, or mock service expects text. Choose one or two passes based on the documented wrapper depth, then parse the parent fixture to catch a misplaced quote.
Put a request body inside a log message or event envelope without letting its quotation marks end the outer string. Escaped line breaks also make multiline values transportable when the log field is a JSON string.
Prepare JSON string contents for tests, documentation examples, and source snippets. The escaping here follows JSON string rules only; add any separate quoting required by JavaScript, Python, a shell, or another host language.
Know the boundary
JSON escaping is specific to JSON. It does not make arbitrary text safe to concatenate into an SQL statement, HTML page, shell command, URL, or programming-language literal. Those contexts interpret different characters and have different security rules. For database queries, use parameterized queries. For HTML, use context-aware output encoding. For a shell or language literal, follow that environment's quoting rules as a separate step.
The distinction prevents a common copy-and-paste bug: a string can be valid JSON and still be unsafe or invalid in the next language that consumes it. Treat this page as a JSON string escaping step, not a universal sanitizer or encoder.
Private by design
The editor uses browser JavaScript to parse, format, minify, escape, and unescape text. Copying, downloading, loading a sample, and reading a local file are browser actions too. The page does not need to send the JSON body to an escape service, so you can work with test payloads without creating a server-side copy.
As with any browser page, avoid pasting a secret into a shared screen or a browser session you do not control. For production credentials, remove or replace sensitive values before saving examples in tickets, fixtures, or documentation.
Quick reference
| Input character | JSON form | Why it changes |
|---|---|---|
| Double quote (") | \" | Marks a string boundary |
| Backslash (\) | \\ | Introduces JSON escapes |
| Line feed | \n | Cannot appear literally inside a JSON string |
| Carriage return | \r | Cannot appear literally inside a JSON string |
| Tab | \t | Cannot appear literally inside a JSON string |
| Forward slash (/) | / | May stay unescaped in JSON |
Quick answers for common JSON escaping, double escaping, and copy-and-paste problems.
It turns a JSON document or text into characters that can sit inside a JSON string. It adds the required escapes for quotation marks, backslashes, and control characters such as line breaks. This page returns the escaped contents without the surrounding quote marks, so add those when the destination expects a complete string value.
Move from converting a string to inspecting, validating, or repairing the JSON it contains.
Escape and unescape JSON in one workspace.
Recover readable text from escaped strings.
Explore nested JSON with a searchable tree.
Repair common syntax issues before sharing data.
Check a payload against its expected structure.
Learn how to prettify, format, and beautify JSON in Node.js using JSON.stringify, fs module, Express middleware, third-party libraries, and online tools. Includes real code examples.
Learn how to validate JSON data using online tools, JavaScript, Python, and schema validators. Includes common JSON errors, JSON Schema basics, and best practices for developers.
Advanced JSON examples including Schema.org FAQ JSON-LD, API error responses, DynamoDB items, and MongoDB documents. Ideal for testing JSON Viewer and Formatter tools.
Explore enterprise-grade JSON examples including OpenAPI schemas, webhook payloads, Kubernetes and Docker configs, and cloud log monitoring samples for JSON Viewer testing.
Explore a big JSON sample with multiple lists, nested objects, and real-world data points. Perfect for testing JSON Viewer, JSON Formatter, and large API responses.