GENERAL TOOL

String to JSON Converter

Turn an escaped or stringified string back into formatted JSON. Paste your own text over the sample to convert it.

Last reviewed: October 6, 2026

An escaped string, a log line, a string literal copied from code, or plain JSON you want formatted. Ctrl or ⌘ + Enter converts.
Converted in your browser. The text is not uploaded, logged or saved.
Valid JSON
Object, 8 keys
Removed 1 layer of string escaping to reach the JSON inside.
{
  "event": "payment.captured",
  "id": "pay_7Hk2LxQ9",
  "amount": 249900,
  "currency": "INR",
  "method": "upi",
  "notes": {
    "invoice": "INV-1042",
    "customer": null
  },
  "retries": 0,
  "live": true
}
Top-level typeObject
Keys8
Nesting depth2
String layers removed1
Size199 B in, 215 B out

More General tools

What is the String to JSON Converter?

This converter takes text that has JSON locked inside a string and gives you the JSON back. That is the situation whenever a payment gateway posts a webhook whose body is one long quoted line, a log viewer shows a whole API response inside a single field, or a database column stores a payload as text. The data is intact. It has been written out as a string, with a backslash in front of every quote, and nothing can read it as an object until that wrapping comes off.

It works in both directions. String to JSON removes the wrapping, checks what is left against the JSON grammar and prints it indented. JSON to string does the reverse and produces the single escaped line you need when a document has to travel inside another document, a config value or a line of code.

All of it happens in this page. The text you paste is not uploaded, and it is not kept in your browser once you leave, which matters because the payloads people paste into a tool like this are usually real ones.

What each input means

Convert
The direction. String to JSON unwraps and formats. JSON to string minifies a document and escapes it into one quoted line.
Text to convert
An escaped string, a log line, a string literal copied out of code, or ordinary JSON you only want formatted or checked. Sample loads an example, Paste reads the clipboard, Open file reads a file on your device, and you can also drop a file onto the box.
Indent
How each nested level is set in: two spaces, four spaces or a tab. Minified removes every optional space and line break to give the smallest valid form.
Key order
As written keeps every key where the source put it. Sorted arranges the keys of every object alphabetically at every depth, which makes two payloads comparable line by line. Arrays are never reordered, because their order is data.
JSON inside string values
An envelope often carries a second document as text inside one of its fields. Expanding turns those fields into real objects so the whole structure can be read at once. It changes the type of the field from string to object, so leave it off for anything you will send back.

How the conversion works

The text is read by a parser written for this page, not by the one built into the browser. It follows the published JSON grammar exactly: one value per document, keys and strings in double quotes, no trailing commas, no comments. Doing the reading by hand buys two things. The first problem is reported with its line and column and a sentence naming the rule that was broken, worded the same in every browser. And nothing is turned into a JavaScript number or object on the way through, so a nineteen-digit order ID comes out with all nineteen digits, 1.0 stays 1.0, and keys stay in the order they were written.

If the value that comes back is itself a string, the converter looks inside it. When that string holds JSON it is read again, and again if needed, until an object or an array appears. Each pass is one layer of encoding and the result panel counts them. A queue that stores a message as a string, behind an API that returns its response as a string, produces two layers, and without this you would convert twice by hand. A string that only resembles a value is left alone: "42" stays a string, because turning it into the number 42 would change your data.

Two near misses are repaired, and the note under the result says so when it happens. Escaped text that has lost its outer quotes, which is how most log viewers hand it over, is treated as the string it used to be. A literal copied from source code with single quotes or backticks around it has them taken off. Everything else that breaks the grammar is reported as an error, on purpose. A converter that quietly accepted single-quoted keys or a trailing comma would hand you output that looks fine here and fails in the system you paste it into.

In the other direction the JSON is first reduced to one line with the space between tokens removed. Every quote and backslash in that line is then escaped and the result is wrapped in double quotes. Text that is not JSON is escaped exactly as typed, which is what you want for a multi-line message or a Windows file path.

Method: Read the text as JSON. While the value is still a string that itself holds JSON, read that string again. Then write the value out with the chosen indent.

What stops a string converting, and the fix

Each of these is valid somewhere: in JavaScript source, in Python, in JSON5, or in a config format that allows comments. None of them is JSON. The converter names the rule and points at the character.

What stops a string converting, and the fix
What was pastedWhy it failsWrite it as
{"a": 1,}A comma after the last entry{"a": 1}
{'a': 'x'}Single quotes{"a": "x"}
{a: 1}The key has no quotes{"a": 1}
{"a": 1} // noteA commentThe same line without the comment
{"a": NaN}Not a JSON value{"a": null}
{"ok": True}Python spelling, with a capital{"ok": true}
{"a": 007}Leading zeros on a number{"a": 7} or {"a": "007"}
{“a”: 1}Curly quotes from a document or chat app{"a": 1}

Getting the most out of the result

  • Read the note under the result before you copy anything. It says how many layers of escaping were removed and whether a repair was made, and that tells you what the system producing the text is really sending.
  • Keep the key order as written while you are debugging, so the output lines up with the source. Switch to sorted keys when you want to compare two payloads, because a diff of two sorted documents shows only the real differences.
  • Use Swap to prove a round trip. Convert, swap, and convert again. If you arrive back at the text you started with, nothing was lost in either direction.
  • When a conversion fails, press Go to error. The cursor lands on the character the parser could not accept. The actual slip is often a few characters to its left: a missing comma or closing quote at the end of the previous line.
  • Minified output is the form to paste into an environment variable or a one-line config field. Indented output is for reading and for version control, where one value per line keeps changes small.
  • For a log file with one JSON document per line, convert a line at a time. Several documents pasted together are not one JSON value, and the error will point at the place the second one starts.

Common mistakes to avoid

The most common mistake is treating a JavaScript object literal as JSON. The two look alike, and JavaScript allows single quotes, bare keys, trailing commas and comments that JSON forbids, so text copied from source code or a browser console usually needs correcting before it converts. The second is unescaping by hand with find and replace. Deleting every backslash also deletes the ones that belong to the data, such as the \n inside a message or the separators in a Windows path, and the result is subtly wrong instead of obviously broken. The third is removing one layer and stopping, then wondering why the receiving code still sees a string where it expected an object. The fourth is trusting a formatter that turns numbers into JavaScript numbers along the way: an identifier longer than about sixteen digits is rounded without warning, and the rounded value will not match the record you are looking for.

Frequently asked questions

How do I convert a string to JSON?

Paste the string into the box with Convert set to String to JSON. The converter removes the escaping, checks the result and shows it indented. It runs as you type, and Ctrl + Enter (⌘ + Enter on a Mac) runs it again. Then copy the output or download it as a .json file.

What is the difference between a JSON string and a JSON object?

A JSON object is structured data: keys and values inside braces. A JSON string is text inside double quotes. When people say “a JSON string” they usually mean an object that has been serialised into text, and sometimes that text has then been encoded again as a string value with all its quotes escaped. This tool reads both and tells you which one it found.

How do I remove the backslashes from a JSON string?

Convert it instead of deleting them. Each backslash marks an escaped character, and removing them all with search and replace also removes the ones that are part of your data. Reading the text as a string undoes exactly one layer of escaping and leaves the rest as it was.

Why does my JSON fail with single quotes or a trailing comma?

The JSON grammar allows neither, even though JavaScript and Python do. Strings and keys need double quotes, and the last entry of an object or array cannot be followed by a comma. The error message names the rule and gives the line and column.

What does double-encoded JSON mean?

It is JSON that has been turned into a string more than once. One system serialises an object to text, then another treats that text as a value and serialises it again, escaping every quote. It shows up as a line full of \", or \\\" when it has happened twice. The converter unwraps every layer in one pass and reports how many there were.

Is the text I paste sent to a server?

No. The conversion is done by JavaScript running in this page, and the text is neither uploaded nor written to browser storage. Opening a file reads it on your device in the same way. Where analytics is switched on, it records that a conversion happened and never what was converted.

Will large numbers such as IDs be changed?

No. A number is kept as the digits it arrived as and is never converted to a JavaScript number, so an eighteen or nineteen digit identifier, a value written as 1.0 or an exponent such as 1e5 comes out exactly as it went in.

How do I convert JSON back into a string?

Set Convert to JSON to string. The document is reduced to one line, its quotes and backslashes are escaped, and the result is wrapped in double quotes, ready to paste into code or into a field of another JSON document. The Swap button moves the current output into the input and flips the direction for you.

Can it convert a Python dictionary or a JavaScript object?

Only once it is written as JSON. A Python dictionary printed with single quotes, True, False or None, or a JavaScript object with bare keys, is reported as invalid along with the first rule it breaks. Print the value with json.dumps in Python or JSON.stringify in JavaScript, and either gives text this tool will read.

How large a file can it handle?

Files up to 10 MB can be opened, and a document of a couple of megabytes converts in a second or two on an ordinary laptop. Very long output is shown without colour, because colouring that much text slows the page more than it helps.

Related calculators