JSON Encode Online
Paste any string and get the JSON-escaped version — quotes, backslashes, and control characters are escaped so the result can be safely embedded in a JSON document.
Last updated: May 26, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is JSON Encode Online?
JSON string values follow strict escaping rules: double quotes (`"`), backslashes (`\\`), and control characters (newlines, tabs, etc.) must be escaped with a leading backslash. Forgetting to escape one of these characters produces an invalid JSON document that parsers will reject.
This tool encodes any input string to a valid JSON string literal. It uses the browser's built-in `JSON.stringify` for the core escaping, then offers optional extras: Unicode escaping (replacing non-ASCII characters with `\uXXXX` sequences for ASCII-only output), forward slash escaping (used when embedding JSON inside an HTML `<script>` tag to prevent `</script>` injection), and the choice of whether to include the surrounding double quotes.
How to Use JSON Encode Online
Type or paste the string you want to encode into the input panel.
Toggle the escape options you need.
The JSON-encoded output appears instantly on the right.
Click Copy and paste the encoded string into your JSON document or code.
Common Use Cases
- Embedding user-provided text into a JSON config file without breaking the syntax.
- Preparing a string with special characters for use in a JSON API request body.
- Generating an ASCII-only JSON literal for systems that do not support UTF-8.
- Safely embedding JSON inside an HTML <script> tag by escaping forward slashes.
- Producing a JSON-safe string for inclusion in a JavaScript source file.
Example Input and Output
A multi-line string with quotes is encoded to a single-line JSON string literal.
Hello "World"
Line 2"Hello \"World\"\nLine 2"Privacy
All encoding happens in your browser. No string is sent to a server.
Reverse operation
To unescape an already-encoded JSON string back to plain text, use the JSON Decode Online tool.

