Skip to content
StringToJSON

JSON → String

Convert JSON to a string, online and instantly.

Minify, escape and quote a JSON document in one step, so it can live inside another string without breaking your syntax.

JSON

0 B

String literal

0 B

Output appears here.

Ready. Paste something above.

Everything runs locally in your browser — your data never leaves this page. Press⌘/Ctrl +Enter to run.

When you need JSON as a string

Most of the time JSON is the outer layer. Occasionally it has to become the inner one: a fixture embedded in a test file, a request body pasted into a shell script, a config value that a provider only accepts as a single string, or a column in a database seed.

Doing that by hand means escaping every quote and collapsing every newline — a job that is tedious once and error-prone every time after. This converter runs the document throughJSON.stringify twice: once to serialize the value compactly, once to escape that text into a literal.

It works the same whether you paste a JSON object, an array, a whole file's contents, or a response you copied out of a browser's network tab. Anything that parses as JSON can be converted to a string; the output is always exactly one line.

Example

// input
{
  "retries": 3,
  "path": "C:\\logs\\app.log"
}

// output
"{\"retries\":3,\"path\":\"C:\\\\logs\\\\app.log\"}"

Language notes

  • JavaScript / TypeScript — the quoted output pastes in directly. For long payloads a template literal is easier to read, but remember backticks and ${ still need escaping.
  • Python — the escaped output is valid in a normal "..." string. Avoid raw strings (r"..."): they will keep the backslashes literal.
  • Java / C# — use the quoted output as-is, or drop the quotes and paste into a text block (""") if your language version supports one.
  • Shell — wrap the unquoted output in single quotes so the shell does not re-interpret the backslashes.

The equivalent in code

// JavaScript — object to a JSON string
JSON.stringify(obj)                    // compact
JSON.stringify(JSON.stringify(obj))    // escaped literal

# Python
json.dumps(obj)
json.dumps(json.dumps(obj))

// Java (Jackson)
mapper.writeValueAsString(obj);

// C#
JsonSerializer.Serialize(obj);

The double call is what turns a document into a literal: the first pass produces JSON text, the second escapes that text so it survives being embedded in another string. That is exactly what this page does, which is why the output pastes into source code without further editing.

Going back the other way

A literal produced here is round-trippable. Paste it into thestring to JSON converter and you get the indented document back. If you only need the escaping rules applied to arbitrary text rather than to a parsed document, theescape tool does that without requiring valid JSON as input.

One operation, several names

People ask for this in a lot of ways: convert JSON into string online, JSON to JSON string online, JSON convert to string online, or simply convert JSON to JSON string. So does "stringify", the name JavaScript gave it, which is why you will also see people searching for a JSON to stringify converter. There is no meaningful difference between any of them — the JSON to string conversion online is the same minify-then-escape step whatever you call it, and this page performs it identically in every case.

The one genuine distinction is whether you want the surrounding quotes. A complete string literal includes them and can be pasted directly into source code. Without them you get just the escaped body, which is what you want when the destination supplies its own quoting. ToggleWrap in quotes to switch between the two.

Think twice before shipping it

Converting JSON to a string is the right answer for a fixture, a one-off config value or a reproduction case in a bug report. It is usually the wrong answer for an API. A stringified payload inside a JSON response means every consumer has to parse twice, no schema tool can see inside it, and logs become unreadable at exactly the moment you need them. If you find yourself embedding a document in a field, check whether a nested object would do instead — it almost always would.

The legitimate exceptions are narrow: a field whose contents are genuinely opaque to your service and are only passed through, a signature that must cover an exact byte sequence, or a storage column whose schema you do not control. In those cases the double encoding is load-bearing, and the important thing is that it is deliberate rather than accidental.

Frequently asked questions

How to convert JSON to a string?
Paste the document into the left pane. This tool minifies it, then escapes every quote, newline and tab so the whole thing becomes a single-line literal. Copy the result, or turn Wrap in quotes off if the destination already supplies its own quotes.
How to convert a JSON object to a string?
Same conversion — an object is just JSON whose top-level value is {…}. Paste it here. In code: JSON.stringify(obj) in JavaScript, json.dumps(obj) in Python, mapper.writeValueAsString(obj) in Java, JsonSerializer.Serialize(obj) in C#.
Should I keep the surrounding quotes?
Keep them when you are pasting a complete literal into JavaScript, Python or JSON. Turn the Wrap in quotes option off when you are pasting into something that already supplies its own quotes — a YAML value, a shell heredoc, or a test fixture builder.
Does it minify first?
Yes. The document is re-serialized compactly before escaping, so the literal never carries the whitespace you were only using to read it.
How to convert the literal back into JSON?
Paste it into the String to JSON converter — it unwraps escaped literals back into an indented document.