WebToolsPlanet
from accidentally closing the tag."}},{"@type":"Question","name":"Does the tool send my text anywhere?","acceptedAnswer":{"@type":"Answer","text":"No. All encoding runs locally in your browser."}}]}
Developer Tools

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

Client-Side Processing
Input Data Stays on Device
Instant Local Execution

Find this tool useful? Support the project to keep it free!

Buy me a coffee

What 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

1

Type or paste the string you want to encode into the input panel.

2

Toggle the escape options you need.

3

The JSON-encoded output appears instantly on the right.

4

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.

Plain string
Hello "World"
Line 2
JSON-encoded
"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.