{ }JSON Stringify

JSON escape · JS object literal

JSON Stringify: Escape JSON into a String Literal

Free online JSON stringify tool: escape JSON into a quoted string literal you can paste into code, or unescape it back to readable JSON in your browser.

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.

Is this tool free, and do I need an account or any software?

It is free, and there is no account, no signup and no download. The page is plain JavaScript running in your browser tab, so opening it is the whole install: paste, convert, copy, close the tab.

What is the difference between JSON stringify and JSON minify?

Stringify turns a value into JSON text and escapes it so it can sit inside another string: {"name":"Ada"} becomes "{\"name\":\"Ada\"}". Minify keeps the text as JSON and only strips whitespace: { "name": "Ada" } becomes {"name":"Ada"}. Use Escape/Stringify when you need JSON embedded in code, logs or URL parameters; pick the Minified indent when you only want a smaller JSON document.

Is JSON stringify the same as serialize?

They are not the same word. Serializing is the general idea — turning a value into a format you can store or send, and that format can be JSON, XML, CSV or anything else. JSON.stringify is JavaScript's implementation of that idea for JSON. So stringify does serialize, but not everything you serialize has to be JSON.

Is it safe to paste JSON with API keys or customer data into an online stringifier?

Only paste into a tool you trust, and assume any server-side tool may log what you send. This one converts inside your browser tab: the JSON is never uploaded, and nothing is kept after the tab closes. If the payload holds live keys, replace those values with dummies first, or run JSON.stringify(JSON.parse(text)) in your own browser console instead.

Can I stringify a JSON file instead of pasting the text?

There is no upload box here, by design: open the JSON file in any editor, copy the contents into the input pane and convert, so the file never leaves your disk. With many files, a short local script does the same thing — read the file, JSON.parse it, then JSON.stringify the text — with no website involved.

What about circular references, BigInt or sorted keys in JSON.stringify?

Three limits worth knowing: a circular object throws a TypeError, a BigInt value throws, and key order follows the order the keys were inserted. A replacer function, a toJSON method or a manual copy fixes most of these cases; for sorted keys and BigInt support, libraries such as safe-stable-stringify and SuperJSON exist. The JSON.stringify in JavaScript page on this site covers the replacer and circular-reference cases with code.

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 straight into a JavaScript or TypeScript file. Choose the wrapper the snippet needs: the const data = prefix, the export default prefix, or no wrapper at all.

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.

Can I use this JSON stringifier on my phone?

Yes. The page is one responsive HTML page, so it works in Safari on iPhone and Chrome on Android: paste the JSON, tap Convert, then tap Copy result. Very large payloads are slower on a phone because all the work happens on the device.