JSON Escaper

Convert raw JSON objects, JSON strings, and multiline text into properly escaped string representations for cURL requests, bash scripts, and database queries.

How to Use the JSON Escaper Tool

1

Input String

Paste raw JSON payload or text on the left, click Upload, or click Sample.

2

Select Mode

Choose Standard quotes (\"), Slashes (\/), Single quotes (\'), or Plain text.

3

Copy Result

Escapes instantly in real time. Click Copy to export for cURL, SQL, or shell scripts.

Tool Options

Double Quote & Control Escaping

Escapes double quotes (\"), backslashes (\\), tabs (\t), and newlines (\n).

cURL & Bash Ready

Generates sanitized payload strings suitable for embedding directly inside cURL -d JSON data flags.

Safe SQL & Log Ingestion

Prevents syntax errors when storing stringified JSON payloads inside SQL database text columns.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

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

  1. 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.
  2. 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.
  3. 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?

  1. 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.
  2. Choose Escaping Mode:
    • Select your mode from the top toolbar: Standard (\"), Slashes (\/), Single (\'), or Plain Text.
  3. 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.

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));
    }
}

Frequently Asked Questions (FAQ)

Why do JSON strings need to be escaped in cURL and shell commands?

Command-line shells and cURL use double quotes to denote string arguments. Unescaped quotes inside JSON payloads terminate the argument prematurely, causing syntax errors or script crashes.

What characters are escaped by a JSON escaper?

Double quotes (") are escaped to \", backslashes (\) to \\, newlines to \n, carriage returns to \r, tabs to \t, and control characters to unicode escape sequences (\u0000).

Why escape forward slashes (\/) in JSON strings?

Escaping forward slashes to \/ prevents browsers from misinterpreting closing HTML script tags when embedding JSON data directly inside script blocks, protecting against cross-site scripting (XSS).

What is the difference between JSON escaping and JSON unescaping?

Escaping adds backslashes before quotes and control characters to turn JSON into a safe flat string literal, while unescaping removes the backslashes to restore the raw JSON object tree.

How to escape a JSON string from the command line using jq or Python?

In Linux/macOS Bash with jq, run jq -R -s "." data.json. In Python, run 'python -c "import json; print(json.dumps(open(\'data.json\').read())[1:-1])"'.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.