What does the JSON Escaper do?
The JSON Escaper converts raw JSON documents, nested objects, and multiline text into properly escaped string representations in real time. Executing 100% in-browser on blueutils.com, it inserts backslashes (\) before special control characters—including double quotes (\"), line breaks (\n), carriage returns (\r), tabs (\t), and backslashes (\\)—making payloads safe for CLI arguments, cURL -d options, shell variables, and SQL database columns.
- Real-Time Client-Side Escaping: Performs zero-latency escaping with automatic input size and output size comparison (
X B → Y B). - Flexible Quoting & Slash Modes: Supports Standard double quotes (
\"), Forward Slashes (\/), Single quotes (\'), and Plain Text modes. - Line & Column Syntax Validation: Validates JSON structure before escaping, pinpointing formatting issues and highlighting the failing line number in red.
Core Concepts & Technical Specifications
- Control Character & Quote Transformation:
- Double Quotes (
") →\": Prevents command-line shells, cURL arguments, and JSON string properties from terminating boundaries prematurely. - Newlines (
\r\n/\n) →\n: Flattens multiline payloads into single-line safe strings for Unix pipes, message brokers, and logs. - Backslashes (
\) →\\: Retains escape sequence integrity when nested inside secondary serialization formats.
- Double Quotes (
- Specialized Escaping Modes:
- Standard (
\"): Standard JSON string escaping for cURL, REST clients, and API request bodies. - Slashes (
\/): Escapes forward slashes to prevent closing</script>tag collisions when embedding JSON in HTML. - Single Quotes (
\'): Escapes single quotes for insertion into SQL string literals and single-quoted bash scripts. - Plain Text: Escapes raw arbitrary text strings without requiring valid JSON syntax.
- Standard (
- In-Browser Privacy & Performance:
- Payload conversion runs strictly in client-side JavaScript memory.
- No data is transmitted to remote servers or stored in database logs.
How to use the tool?
- Supply JSON or Text Payload:
- Paste a raw JSON document or string into the left editor, click Upload to load a local file, or click Sample to load a pre-configured JSON object.
- Choose Escaping Mode:
- Select your mode from the top toolbar: Standard (
\"), Slashes (\/), Single (\'), or Plain Text.
- Select your mode from the top toolbar: Standard (
- Copy or Download:
- Escaped text is generated instantly in the right editor. Click Copy to copy to your clipboard or Download to save as
output.txt.
- Escaped text is generated instantly in the right editor. Click Copy to copy to your clipboard or Download to save as
Pipeline & Contextual Workflows
- cURL Command Preparation: Paste a multi-line JSON payload here to escape quotes, then embed the string directly into a terminal
curl -d "..."command. - Reversible Restoration Pipeline: Convert escaped JSON strings back into formatted, indented objects using JSON Unescaper.
- Whitespace Optimization: Strip unnecessary indentation with JSON Minifier & Compressor before escaping to produce minimal payload sizes.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/json/escaper) for automated continuous integration, backend services, and deployment pipelines.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText / json |
String / Object | Raw JSON payload string or parsed native JSON object to escape. | {"service":"auth","active":true} |
escapeSlashes |
Boolean | Optional. When true, converts forward slashes / to \/. Defaults to false. |
true |
escapeSingleQuotes |
Boolean | Optional. When true, converts single quotes ' to \'. Defaults to false. |
false |
allowPlainText |
Boolean | Optional. When true, skips JSON syntax validation and escapes raw text. Defaults to false. |
false |
API Request Payload Examples
cURL (Using Direct JSON Object)
curl -X POST https://blueutils.com/api/json/escaper \
-H "Content-Type: application/json" \
-d '{
"json": {
"appName": "blueutils.com",
"status": "active"
}
}'cURL (Using Raw String & Options)
curl -X POST https://blueutils.com/api/json/escaper \
-H "Content-Type: application/json" \
-d '{
"rawText": "{\"path\": \"/api/v1/auth\"}",
"escapeSlashes": true
}'Python
import requests
url = "https://blueutils.com/api/json/escaper"
payload = {
"json": {
"appName": "blueutils.com",
"status": "active"
},
"escapeSlashes": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"rawText": "{\\"appName\\":\\"blueutils.com\\",\\"status\\":\\"active\\"}"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/json/escaper"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether the escaping operation succeeded. | true |
result |
String | Escaped JSON result string with backslashes. | "{\\\"appName\\\":\\\"blueutils.com\\\"}" |
data |
Object / Array | Parsed native object/array representation returned when input is valid JSON. | {"appName":"blueutils.com"} |
originalSize |
Number | Byte length of original input string. | 45 |
resultSize |
Number | Byte length of escaped output string. | 67 |
error |
String | Detailed error explanation returned on invalid syntax. | "Invalid JSON syntax: Unexpected token '}' (Line 2)" |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"result": "{\\\"appName\\\":\\\"blueutils.com\\\",\\\"status\\\":\\\"active\\\"}",
"data": {
"appName": "blueutils.com",
"status": "active"
},
"originalSize": 45,
"resultSize": 67
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid JSON syntax: Unexpected token '}' at line 3 column 1"
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to escape JSON?
Programmatic JSON escaping avoids syntax errors across multi-language pipelines:
- Automated cURL Command Generation: Generates escaped JSON parameters dynamically for integration test runners and CLI wrappers.
- SQL & Database Ingestion: Ensures JSON payloads can be safely embedded into string literals in raw SQL queries without quote collisions.
- LLM Context Minimization & Accuracy: AI agents often produce incorrect backslash counts when serializing stringified JSON; API execution delivers deterministic escaping.
Native Usage
Escape JSON strings locally across terminal environments and programming runtimes:
Browser DevTools Console
// Escape any string directly in browser console
JSON.stringify(rawText).slice(1, -1);Linux / macOS (jq CLI)
# Escape JSON string using jq
jq -R -s '.' data.json | sed 's/^"//;s/"$//'Windows (PowerShell)
# Escape JSON string using PowerShell
(Get-Content data.json -Raw | ConvertTo-Json -Compress) -replace '"', '\"'Python
import json
data = {"appName": "blueutils.com", "status": "active"}
raw_text = json.dumps(data)
escaped_text = json.dumps(raw_text)[1:-1]
print("Escaped:", escaped_text)Node.js
const raw = JSON.stringify({ appName: 'blueutils.com', status: 'active' });
const escaped = JSON.stringify(raw).slice(1, -1);
console.log('Escaped:', escaped);Java (Jackson)
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static void main(String[] args) throws Exception {
String rawJson = "{\"appName\":\"blueutils.com\",\"status\":\"active\"}";
ObjectMapper mapper = new ObjectMapper();
String escaped = mapper.writeValueAsString(rawJson);
System.out.println(escaped.substring(1, escaped.length() - 1));
}
}