JSON Escape

    Escape JSON into a safe string for logs, APIs, config files, and language literals.

    Browser only Valid JSON Input
    JSON Input
    23 lines
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    Choose escape depth

    2× escapes one additional string layer. A quote may show three backslashes; forward slashes stay unchanged.

    Escaped Output
    1 line
    1
    Input chars
    447
    Output chars
    0
    Escapes
    0
    Lines
    23

    A practical guide to JSON strings

    Escape JSON for a string, wrapper, or log entry

    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.

    JSON escape online
    JSON string escape
    Double escape JSON
    Escape quotes and backslashes
    JSON newline escape
    Format and minify JSON

    Before and after: a webhook handoff

    The payload is fine. Its new container needs a different view of it.

    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.

    Before · webhook JSON

    {"event":"payment.failed","message":"Card declined"}

    After · one string layer

    {\"event\":\"payment.failed\",\"message\":\"Card declined\"}

    After · two string layers

    {\\\"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

    What JSON escaping changes

    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

    1× or 2× JSON escaping?

    Escape JSON 1×

    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.

    Escape JSON 2×

    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

    How to use the JSON escape tool

    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.

    01

    Paste the source

    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.

    02

    Pick the destination

    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.

    03

    Choose 1× or 2×

    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.

    04

    Review and copy

    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

    From webhook body to fixture string

    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.

    API fixtures and nested payloads

    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.

    Webhook and application logs

    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.

    Readable code samples

    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

    What this tool does not escape

    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

    Your text stays in this browser

    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

    Common JSON escape sequences

    Input characterJSON formWhy it changes
    Double quote (")\"Marks a string boundary
    Backslash (\)\\Introduces JSON escapes
    Line feed\nCannot appear literally inside a JSON string
    Carriage return\rCannot appear literally inside a JSON string
    Tab\tCannot appear literally inside a JSON string
    Forward slash (/)/May stay unescaped in JSON

    JSON escape questions

    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.

    Complete JSON toolkit

    Move from converting a string to inspecting, validating, or repairing the JSON it contains.