Tools

Home
JSON FormatterSQL FormatterJS ValidatorMinify CSS
Merge PDFCompress PDFImage to PDF
JPG to PNGPNG to WebPCrop Image

JSON String Encoder

Escape and unescape special characters in JSON strings — handles quotes, backslashes, newlines, tabs, and unicode

Your files never leave your browser
Input0 chars, 0 lines
Output0 chars, 0 lines
Ready·Ctrl+Enter to encode

Paste raw text in, get a properly escaped JSON string out — quotes, backslashes, newlines, tabs, and Unicode all handled. Hit Decode to go the other direction and turn \n and \" back into readable characters.

Useful when you're hand-building JSON payloads or pulling strings from logs that need to sit inside a "value" field without breaking the parser. And everything runs in your browser. Nothing gets uploaded.

How It Works

Paste Raw Text
➜
Escape Special Chars
➜
JSON-Safe String

The encoder scans each character in your input. Regular letters and numbers pass through untouched. When it hits a double quote, backslash, newline, carriage return, tab, or any control character, it swaps it for the correct JSON escape sequence. Unicode characters above the ASCII range get converted to \uXXXX hex notation. Decoding reverses the whole process — it reads each escape sequence and replaces it with the original character.

Examples

Embedding a file path in JSON

Windows paths have backslashes that break JSON strings if left unescaped.

INPUT
C:\Users\admin\report.csv
OUTPUT
C:\\Users\\admin\\report.csv

Multi-line error message for an API response

You have a stack trace with line breaks and quotes that needs to go inside a JSON "message" field.

INPUT
Error: "file not found" at line 42 in parser.js
OUTPUT
Error: \"file not found\"\n at line 42\n\tin parser.js

Decoding an escaped Unicode string back to readable text

An API returned JSON with Unicode escapes. You want to read the actual characters.

INPUT
Caf\u00e9 \u2014 open from 9\u201315
OUTPUT
Café — open from 9–15

Who Uses This

💻 Backend Developers

Building JSON payloads with user-generated content that contains quotes or special characters.

🛠 DevOps Engineers

Embedding config values with backslashes and paths into JSON configuration files.

📊 QA Testers

Crafting test payloads with edge-case characters to check if an API handles escaping correctly.

📝 Technical Writers

Preparing code examples for documentation where JSON strings need correct escaping to be copy-pasteable.

Common Mistakes

Double-escaping backslashes

You encode a string that was already escaped. Now \n became \\n and your output has literal backslash-n instead of a line break. Always start with the raw, unescaped text.

Forgetting to strip the outer quotes

You paste a JSON value like "hello\nworld" with the surrounding quotes into the decoder. This tool handles that automatically — it strips wrapping quotes — but if you add extra quotes yourself, you will get unexpected results.

Mixing up encoding direction

Clicking "Decode" when you meant to encode. If your input is plain text with actual newlines and you hit decode, you get the same text back (or an error if there is a stray backslash). Check which button you're pressing.

Technical Details

Frequently Asked Questions

What characters need to be escaped in a JSON string?

Double quotes, backslashes, and control characters (like newline, tab, carriage return) must be escaped. The JSON spec also allows escaping the forward slash, though most parsers don't require it. Any character outside the basic ASCII range can optionally be escaped using \uXXXX notation.

How do I encode emoji in JSON?

Most emoji sit outside the Basic Multilingual Plane, so they need two \uXXXX sequences called a surrogate pair. For example, the grinning face 😀 becomes \uD83D\uDE00. This tool handles surrogate pairs automatically — just paste the emoji and hit encode.

What is the difference between JSON encoding and URL encoding?

Different formats, different rules. JSON encoding escapes characters that break JSON syntax (quotes, backslashes, control chars) using backslash sequences. URL encoding replaces unsafe URL characters with percent-encoded values like %20 for a space. You would not use one in place of the other.

Can I encode an entire JSON object with this tool?

This tool is specifically for encoding the value part of a JSON string — the text that goes between the quotes. If you paste a full JSON object like {"key": "value"}, it will escape the braces, colons, and quotes, which is probably not what you want. For formatting whole JSON documents, try the JSON Formatter instead.

Is this tool safe for sensitive data like API keys?

Yes. All processing happens locally in your browser using JavaScript. Nothing is sent to a server, nothing is logged, and nothing persists after you close or refresh the page. It is as private as typing into a local text editor.

Share: