DevFormatLab

JSON → String

Escape for code

Paste JSON on the left and get an escaped string on the right, ready to embed in code.

InputValid
Output

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

  1. Paste JSON text or a JS value into the input panel.
  2. Click Convert to produce an escaped string in the output panel.
  3. 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

Canonical: https://devformatlab.com/en/json-to-string