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.
Frequently Asked Questions
What is the difference between encoding and JSON.stringify?
JSON.stringify on a string is essentially what this tool does — it returns the escaped, quoted form. This tool wraps that with extra options (Unicode escape, slash escape, optional quotes) for specific use cases.
Why would I escape forward slashes?
The JSON spec does not require it, but it is common when embedding JSON inside an HTML <script> tag — escaping / prevents the sequence </script> from accidentally closing the tag.
Does the tool send my text anywhere?
No. All encoding runs locally in your browser.
Related Tools
JSON Decode Online
Decode a JSON-escaped string back to plain text. Unescapes quotes, backslashes, newlines, and Unicode \uXXXX sequences. Works with or without surrounding quotes.
JSON Formatter
Format, validate, and beautify JSON instantly — with clear error messages, Tree View, Diff mode, and Schema validation.
JSON Stringify Online
Stringify JSON with full control over indentation, key sorting, Unicode escaping, and JS-call wrapping. Mirrors JSON.stringify with extra options. Copy the formatted result.
JSON Validator
Validate JSON syntax online. Shows valid/invalid status, error location (line and column), and structure stats including type, key count, and depth.
JSON Multiline String
Escape multiline text into a valid JSON string value, or unescape a JSON string back to readable text. Handles newlines, tabs, quotes, and backslashes.
String Escape / Unescape
Escape or unescape strings for JSON, JavaScript, HTML, URL, CSV, and RegEx contexts — instantly.

