{ }JSON Stringify

JSON escape · JS object literal

JSON Stringify: Escape JSON into a String Literal

Turn JSON into an escaped string literal you can paste into JavaScript, Java or PHP, and unescape it back to JSON. Runs in your browser — nothing uploads.

Runs entirely in your browser — nothing you paste is uploaded

JSON input0 chars
Escaped string—

Everything runs in your browser. Nothing is sent anywhere.

What "JSON stringify" means

Every language has a way to turn a structured value into text. In JavaScript it is JSON.stringify: it takes an object or array and returns compact JSON text such as {"name":"Ada","age":36}.

That is already text — but it is not a string literal. If you paste it straight into source code, the inner double quotes end the string early and the code breaks. To embed JSON inside a string you need each double quote escaped with a backslash and the whole thing wrapped in quotes:

const payload = "{\"name\":\"Ada\",\"age\":36}";

That second pass is what this page builds for you, in whichever direction you need.

When you actually need an escaped JSON string

Most people land here for one of these jobs:

  • Hard-coding a fixture. You pasted a real API response into a test file or a seed script and need it as one line, quotes and all.
  • Embedding JSON in another layer. A config value, an environment variable, a database column, a template or a URL parameter that only accepts a string.
  • Debugging an escaped payload. A log line shows a giant quoted blob and you want to see the JSON inside it again.
  • Comparing two versions of a payload. Unescape a stored response and read it the way the server sent it.

How to use the converter

  1. Paste your JSON into the left pane. It does not have to be pretty — the tool parses it first.
  2. Press Convert (or Ctrl/⌘ + Enter).
  3. The right pane holds the result. Copy result puts it on your clipboard, Download saves it as a text file, Clear empties both panes.

Switch to the string → JSON tab for the reverse job. It accepts input with or without the outer quotes, removes the escape sequences, and prints readable JSON at the indent you pick. The third tab, JSON → JS object, is covered further down.

If the input is not valid JSON, you get a message with the line and column plus a snippet of the text around the problem. Fix it in the input box and press Convert again — the tool never rewrites your data behind your back.

Why there are two steps, not one

This trips people up constantly. The first call returns JSON text; the second call returns a string literal of that same text:

JSON.stringify(obj)
// {"name":"Ada","age":36}

JSON.stringify(JSON.stringify(obj))
// "{\"name\":\"Ada\",\"age\":36}"

The difference is one extra pair of quotes and a backslash in front of every inner quote. If your output still starts with { instead of a quote character, you only did the first step.

JSON to a JavaScript object literal

The third tab solves a different problem. Escaping gives you a string; object-literal output gives you the thing you would normally type by hand. Keys that are valid identifiers lose their quotes, string values switch to single quotes, and every entry ends with a trailing comma, so the result drops straight into a formatted file:

const data = {
  name: 'Ada',
  age: 36,
  tags: ['admin', 'beta'],
};

Keys that cannot be identifiers — first name, order-id, 2fa — keep their quotes, and any single quote inside a value is escaped, so the output stays valid JavaScript. Choose const data = , export default , or the bare object depending on where the snippet is going. To get JSON back from a literal you already have, run JSON.stringify on it.

Doing the same thing in your language

  • JavaScript / TypeScript — JSON.stringify(value) for the JSON text, once more for the escaped string. JSON.parse goes back.
  • Python — json.dumps(value) produces JSON text; a second json.dumps on that string produces the escaped literal. json.loads reverses it.
  • PHP — json_encode($value) for JSON text. Wrap and escape with json_encode(json_encode($value)).
  • Java — no built-in one-liner; Jackson's ObjectMapper.writeValueAsString produces JSON, and calling it twice gives the escaped literal.
  • Go — encoding/json.Marshal gives JSON bytes; marshal the string again for the escaped form.
  • C# — JsonSerializer.Serialize gives JSON; serializing that string again gives the literal.

Every one of them follows the same two-step logic, which is why a converter is faster than remembering the syntax.

Mistakes worth avoiding

  • Single quotes. JSON has no single-quoted strings. Replace them with double quotes before converting. (This only applies to JSON input — the object-literal tab uses single quotes because that is JavaScript, not JSON.)
  • Trailing commas. Allowed in JavaScript objects, rejected in JSON. The error message will point at the comma.
  • Numbers kept as strings. "36" and 36 are different values. If a downstream service validates types, check this before you ship.
  • Treating escaping as protection. A quoted, escaped string is trivial to unescape. It is not encryption and it is not Base64.
  • Huge single-line output. Some editors and terminals choke on a multi-megabyte one-liner. If that happens, keep the pretty version alongside it.

Privacy, plainly stated

The whole conversion happens in your browser using the built-in JSON functions. There is no upload, no account, no logging of your input, and no copy kept after you close the tab. That matters when the payload you are debugging contains real customer records, tokens or internal URLs.

What does JSON stringify actually do?

JSON.stringify turns a value such as an object or array into JSON text. Running it a second time turns that JSON text into a proper string literal with escaped quotes, which is what you can paste into source code. This page does both passes in one click.

How do I convert JSON to a JavaScript object literal?

Open the JSON → JS object tab, paste the JSON and press Convert. Keys that are valid identifiers lose their quotes, string values use single quotes, and every entry ends with a trailing comma, so you can paste the result into a .js or .ts file. Pick const data = , export default , or the bare object.

Is my JSON uploaded anywhere?

No. The conversion runs in JavaScript inside your browser. Nothing is sent to a server, logged or stored, so it is safe for payloads that contain customer data or API keys.

How do I go the other way and unescape a string?

Switch to the string → JSON tab, paste the quoted, escaped text, and press Convert. The backslashes are removed and you get readable, indented JSON back. You can pick 2 spaces, 4 spaces or minified output.

Why do I get an error about a position?

The input is not valid JSON yet — usually a trailing comma, a single-quoted key or an unquoted value. The message tells you the line and column, plus the text around the problem, so you can fix it in the input box and convert again.

Is an escaped string the same as encryption or Base64?

No. Escaping only makes the text safe to embed in code; the content stays fully readable once it is unescaped. Base64 and encryption are different things — never treat an escaped or encoded string as protected data.

Can I convert very large JSON files?

Yes up to a point. Everything runs on your device, so speed depends on your machine and browser. Input over about 2 million characters may make the page slow; for huge files, split the payload or use a command-line tool.