JSON ⇄ String

Convert between doubly-escaped strings and JSON

JSON to String: How to Count the Layers, and Why Data Turns Into a String

Which kind of problem this tool solves

Normally a piece of JSON parses into an object and its fields are directly accessible. But in practice you constantly meet the case where what parses out is a string — the shape of the data is wrong, and every field access fails. The root cause is that this JSON was serialized into a string at least once before it ever reached you.

The tool's input is a string literal, and its output is the literal of the data it actually carries; in the other direction it wraps a data literal into a string literal. Deciding which of those two states your current data is in is the first step of any troubleshooting.

How to count how many layers you have

Look at whether the value starts and ends with quotes, and at the number of backslashes inside those quotes:

You seeWhat it isAction
{"a":1}the data itself (0 layers)use directly
"{\"a\":1}"a string holding a JSON (1 layer)parse once
"\"{\\\"a\\\":1}\""a string holding a string holding JSON (2 layers)parse twice

The rule: if the outermost character is a double quote, you must peel off one layer first. After peeling, if the result still begins with a double quote, peel another layer. With every added layer the number of backslashes roughly doubles — that is the most direct clue you have.

Where this kind of data usually comes from

  • Logs. When a structured object is written into a log line it is serialized as a whole, so the payload inside the log is always in string form.
  • Text columns in a database. When the column type is TEXT or VARCHAR, the ORM or driver may have stringified only once, so what you read back is a string, not an object.
  • Environment variables and config. Environment variables can only hold strings, so a JSON config must be serialized before it goes in (a .env file, a Kubernetes ConfigMap, or CI secrets).
  • Message queues and webhooks. The message body is itself a string; if a producer pre-serialized one of its object fields, the consumer receives a nested string.
  • HTTP form fields or query parameters. These can only carry strings, so a complex structure must be serialized before it is transmitted.

Three pitfalls people keep hitting

  • Parsing repeatedly and making it worse. One failed parse does not mean you should parse again. The correct move is to determine the layer count first: parse once and see whether the result is an object or still a string. If it is an object you are already correct — parsing again would turn that object back into a string form and take you further from the goal.
  • Every type changes after a round trip. JSON has only six types (object, array, string, number, boolean, null). A value that was originally a Date, a BigInt, or a Map degrades into a string or a number after serialization, and deserialization will not bring it back. Time fields become strings and large integers lose precision — these must be converted at the application layer.
  • "JSON" wrapped in single quotes. A JSON string can only use double quotes as its delimiter. The single-quote form is JavaScript object-literal or Python-dict syntax, not JSON. The tool rejects single-quoted input outright and points to the location.

How this differs from the escape tool

The escape tool handles the special characters inside a string (quotes, backslashes, newlines) and asks "can this text be safely placed inside JSON". This tool handles the layer count of the whole document and asks "how many times was this data serialized in total". When troubleshooting, first use this tool to pin down the layer count, then reach for the escape tool for the text content when you need it.

How to use this tool

Paste the content into the input box and pick a direction: JSON to string emits a single-line string literal you can drop straight into code or config; string to JSON strips the outer delimiter and restores the inner backslash sequences. Invalid input reports the concrete reason (single quotes, unclosed value, illegal escape) and its position, instead of returning a plausible-looking but wrong result.

FAQ

What is double escaping?

Serializing a JSON as a string once more adds an extra layer of backslashes before quotes, e.g. "{\"a\":1}". This tool peels off layers one by one until it gets the real object.

What does JSON → String do?

It parses the input first, then re-serializes it into a compact single line as normalization; if the input itself is a string, it escapes one more layer.