String to JSON Converter

Convert any plain text string to valid JSON instantly — properly escaped and ready to paste into your code or config file. Choose JSON String to wrap your entire input as a single JSON value, or JSON Array to turn a line-by-line list into a JSON array of strings. All escaping is handled by JSON.stringify() — nothing leaves your browser.

0 characters
 
Ad placeholder — 728×90 desktop / 320×50 mobile

JSON String mode vs JSON Array mode

JSON String mode

Wraps your entire input as a single JSON string value. Uses JSON.stringify(text) under the hood, which handles all required escaping: double quotes become \", backslashes become \\, newlines become \n, tabs become \t, carriage returns become \r, and Unicode control characters (U+0000–U+001F) become \uXXXX sequences.

The result is a standalone JSON string — the outer double quotes are included. You can paste it directly as the value in a JSON object, or use it in any context where a JSON string value is expected. For example:

"Hello\nWorld\n\"Quoted\""

JSON Array mode

Treats each line of your input as a separate string element and produces a JSON array. Blank lines can be excluded with the checkbox. Each element is individually escaped by JSON.stringify().

With pretty-print enabled, the array is indented for readability:

[
  "apple",
  "banana",
  "cherry"
]

With pretty-print off, you get compact single-line JSON:

["apple","banana","cherry"]

What JSON escaping actually does

JSON is a text format, but it has strict rules about which characters can appear inside a string literal. If your text contains any of the following, they must be escaped — otherwise the JSON is invalid and any parser will reject it:

  • Double quote ("): Must become \" — an unescaped quote would end the string prematurely.
  • Backslash (\): Must become \\ — a single backslash is an escape character and would corrupt the next character.
  • Newline: Must become \n — raw newlines inside a JSON string literal are not valid.
  • Carriage return: Must become \r.
  • Tab: Must become \t.
  • Control characters (U+0000–U+001F): Must become \uXXXX sequences.

This converter handles all of these using the browser's native JSON.stringify(), which is the same function your JavaScript runtime uses when serialising JSON. The output is guaranteed to be syntactically valid JSON.

When you need this

  • Hardcoding strings in config files: If your string contains quotes or newlines, naive copy-paste will break your JSON. Run it through this converter first.
  • Building API payloads manually: When constructing a JSON body by hand in Postman, curl, or a similar tool, you need the string value correctly escaped.
  • Converting lists to JSON arrays: If you have a plain-text list (one item per line) from a spreadsheet or document, JSON Array mode gives you a valid array in one step.
  • Embedding multi-line strings in JSON: JSON doesn't support multi-line string literals — newlines must be \n. JSON String mode converts them automatically.
  • Testing and debugging: When you need to quickly verify what a string looks like when serialised — especially if it contains unusual characters.

Frequently asked questions

How do I convert a string to JSON in JavaScript?

Use JSON.stringify(yourString). This returns the string wrapped in double quotes with all special characters properly escaped. For example: JSON.stringify('say "hello"') returns "say \"hello\"". This converter uses the same function, so the output is identical to what you'd get in Node.js or the browser console.

What's the difference between a JSON string and a plain string?

A plain string is raw text. A JSON string is a plain string encoded according to the JSON specification — wrapped in double quotes, with reserved characters escaped using backslash sequences. A JSON string can be safely embedded inside a JSON object or array without breaking the surrounding structure.

Why does my JSON break when I paste text with quotes or backslashes?

Because those characters have special meaning in JSON. A double quote inside a JSON string ends the string at that point. A backslash starts an escape sequence. If you paste unescaped text directly into a JSON value, any quote or backslash will corrupt the structure. Run the text through this converter first to produce a properly escaped version.

Does this validate my JSON as well as convert it?

The output of this tool is always syntactically valid JSON — the conversion produces it from scratch using JSON.stringify(), so it cannot produce invalid output. If you need to validate existing JSON (not convert a string), use a dedicated JSON validator.

Is Unicode text handled correctly?

Yes. JSON.stringify() correctly handles all Unicode text, including emoji, CJK characters, Arabic, and other non-ASCII characters. Characters above U+001F are kept as-is (they don't need escaping in JSON), while control characters below U+0020 are converted to \uXXXX sequences.

Ad placeholder — 728×90 desktop / 320×50 mobile