TinyTools

JSON Escape Online

Convert raw JSON objects into escaped string literals for JavaScript, Java, C#, Python, and cURL commands.

Runs locally in your browser. No strings or payloads are uploaded to any server.
Ready
Raw JSON Input
0 chars 0 lines 0 B
Escaped String Literal
0 chars 0 lines 0 B

How to Escape JSON for Code, CLI & APIs

When embedding JSON payloads into software source code (such as unit tests in Java, C#, Python, or JavaScript), or passing JSON data through terminal commands like curl -d, internal double quotes (") must be escaped with a preceding backslash (\"). Without proper escaping, string interpreters encounter premature quote terminations, resulting in syntax errors. TinyTools JSON Escape turns any JSON object into an escaped string literal tailored for your target environment.

How to Escape JSON Online

  1. Input JSON: Paste your JSON object into the left code editor or click Sample.
  2. Select Language Preset: Choose your target syntax (Generic, JavaScript, Java/C#, Python, or cURL Command).
  3. Toggle Options: Check Minify before escaping to compact the string into a single line, and Wrap in outer quotes if your code requires wrapping quotes.
  4. Copy String: Click Copy String and paste the escaped literal directly into your code editor or terminal.

Code Example: Raw JSON to Escaped Java / C# String

Consider this standard JSON object:

{
  "user": "Sarah Connor",
  "active": true
}

When escaped for Java or C# string literals, all internal quotes are escaped with backslashes and wrapped in double quotes:

"{\"user\":\"Sarah Connor\",\"active\":true}"

Supported Presets & Environments

JavaScript & TypeScript

Generates standard JSON-compliant string literals ready for JSON.parse("...") expressions.

Java & C#

Escapes quotes and newlines for String json = "..."; variables in Spring Boot, ASP.NET, and NUnit tests.

Python Strings

Escapes internal quotes for single-quoted Python strings ('{"a": 1}') or double-quoted literals.

cURL Command Line Payloads

Generates ready-to-run curl -X POST -d '...' commands formatted for Unix Bash or Windows Command Prompt.

Related JSON Tools

Browse All JSON Tools

Frequently Asked Questions

What is JSON escaping?

JSON escaping converts special characters (such as double quotes, backslashes, newlines, and tabs) into their escaped backslash representation (\") so that the JSON payload can be safely embedded inside programming language string literals or CLI commands.

Why do I need to escape JSON in code?

Programming languages like Java, C#, Python, and JavaScript use double quotes to denote string literals. If you paste a raw JSON object with internal quotes into a string variable, the compiler thinks the string has ended, triggering syntax errors. Escaping quotes prevents this.

How does the cURL escaping mode work?

In Unix/Linux terminals, single-quoted JSON can be passed to curl -d '{"key":"value"}'. In Windows Command Prompt (cmd.exe), double quotes must be used and internal quotes escaped: curl -d "{\"key\":\"value\"}". TinyTools supports presets for both.

Can I unescape an already escaped string?

Yes. TinyTools provides a dedicated JSON Unescape companion tool to reverse the process and restore clean, formatted JSON.

Is my data private when escaping online?

Yes. Everything runs 100% locally in your web browser. No payload data is ever uploaded to our servers.