Format Code Now
/

JSON to String Converter

FV-28

Paste JSON and click JSON to string to get one quoted, escaped string you can paste into code or a text field. String to JSON turns such a string back into JSON.

Runs in your browser. Nothing is uploaded.

JSON or a string that holds JSON

Result

How to use it

  1. Paste your JSON into the input box.
  2. Pick a string style: double-quoted, single-quoted JavaScript, a template literal, or escaped with no quotes.
  3. Click JSON to string. Leave the white space option on to get a compact string.
  4. To reverse it, paste the string and click String to JSON.

What the string contains

The input is checked as strict JSON first, so a missing comma is reported with its position instead of being wrapped. By default the white space between tokens is removed, then the whole text is escaped: quotes and backslashes get a backslash and line breaks become \n. Numbers are copied as written, so very large integers are not rounded. Untick the option to keep your indentation inside the string.

Choosing a style

Double quotes give a string that works as a JSON string value and in JavaScript, C# and Java. The single-quoted and template styles use JavaScript rules, and a template literal also escapes backticks and ${. The bare style gives the escaped text with no quotes at all. This is the same as calling JSON.stringify on a JSON string, but you see the result without writing code.

Error messages and what to do

MessageWhat it meansFix
The input is empty.There is nothing to convert.Paste JSON, or use the sample.
The string was unescaped, but what it holds is not valid JSONString to JSON unescaped your text, but the result is not JSON.Check the string for a missing quote, comma or bracket inside the JSON it holds.

Questions people ask

How do I convert JSON to a string?

Paste the JSON and click JSON to string. The tool validates it, removes extra white space if you leave that option on, and escapes it as one quoted string. The result can be pasted into code or sent as a text value.

Why do I see backslashes before every quote?

A string literal uses quotes as delimiters, so each quote inside it must be escaped. The backslashes are not part of your data. When the string is read back, the escapes are removed and the original JSON is restored.

Does it change my JSON data?

Only white space between tokens, and only if you leave the option on. Keys, values, order and number digits stay as written. Untick the option and your indentation and line breaks are kept inside the string as \n escapes.

Can I turn the string back into JSON?

Yes. Paste the escaped string, with or without its outer quotes, and click String to JSON. It is unescaped, checked as JSON and shown indented. If the result is not valid JSON, the error says so.

What is the difference between this and JSON stringify?

JSON.stringify in JavaScript turns a value into JSON text. Here the input is already JSON text, and the tool escapes that text as a string, which is like stringifying twice. It is what you need when JSON must travel inside another JSON field.

About this tool

The input is checked as strict JSON first, so a missing comma is reported with its position instead of being wrapped. By default the white space between tokens is removed, then the whole text is escaped as one string: quotes and backslashes are escaped and line breaks become \n. Numbers, including very large integers, are copied as written. Untick the option to keep your own indentation inside the string. The single-quoted and template styles use JavaScript rules, so a template literal also escapes backticks and ${. String to JSON takes such a string, unescapes it, checks that the result is valid JSON and pretty-prints it. Nothing is uploaded.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.