Processing happens entirely in your browser.
Escape JSON into a code string
Convert JSON text or a JavaScript object into a compact JSON string with internal double quotes and backslashes escaped so it can be placed inside source code string literals without syntax errors. Input accepts raw JSON text or pasted object notation. When the input is a non-JSON string, quotes and backslashes are escaped rather than parsing.
Features
- Accepts JSON string or JS value (object / array)
- Outputs compact JSON with double quotes and backslashes escaped
- If input is non-JSON text, only quotes and backslashes are escaped
- 100% client-side — no network
How to use
- Paste JSON text or a JS value into the input panel.
- Click Convert to produce an escaped string in the output panel.
- Copy and paste the result into your source code string literal.
Frequently Asked Questions
Should I wrap the result with outer quotes?
▾
This tool returns the escaped inner content (no outer quotes). If you need a full JS string literal, wrap the output in quotes in your source.
Related tools
Format, minify, validate and beautify JSON with inline error highlighting.
Compare two JSON documents side-by-side with line-level highlighting and key sorting.
Remove duplicates, empty rows, trim whitespace, convert UTF-8 ↔ Shift-JIS.
Convert YAML ↔ JSON and YAML ↔ Java .properties with strict validation.
Encode and decode Base64 (and Base64URL) for text or files. Real-time, browser-only.
Encode and decode URLs, query strings and URI components with percent-encoding and form-style spaces.
Generate MD5, SHA-1, SHA-256, SHA-384 and SHA-512 hashes for text or files in your browser.
Convert Unix timestamps (seconds or milliseconds) to and from human-readable dates across timezones.
Decode JSON Web Tokens to inspect header, payload and signature, with readable timestamps and expiry status.
Test regular expressions in real time with match highlighting and presets.
Canonical: https://devformatlab.com/en/json-to-string