JSON Stringify
Turn JSON or plain text into one escaped string that you can put inside code, a config file or another JSON document, and turn an escaped string back into the original. It checks your JSON first and points to the exact place of a mistake, can minify it, accepts JavaScript-style objects, and writes the result as a JSON string, a JavaScript string or plain escaped text. Long numbers keep every digit, and everything runs in your browser.
How to use it
- Choose the action: Stringify turns JSON or text into an escaped string; Unstringify turns an escaped string back into the original.
- Add your input: type or paste it, press Open a file (or drop a file onto the box), or press Example. The result updates as you type.
- Stringify options:
- The input is: JSON is checked first and an error is shown with its line and column; Plain text is escaped as it is.
- Write the result as: a JSON string (double quotes), a JavaScript string (single quotes) or just the escaped text without outer quotes.
- Minify JSON first removes spaces and line breaks so the string is short; untick it to keep the text exactly as typed.
- Accept JavaScript-style objects converts single quotes, keys without quotes, comments and trailing commas into strict JSON.
- Escape non-English characters writes them as
\uXXXXso the result is plain ASCII, and Safe inside an HTML script tag also escapes<,>,&and/.
- Unstringify options: paste a quoted string (
"..."or'...') or just the escaped text. If the result is JSON, choose to pretty-print it (2 spaces, 4 spaces or tabs) or leave it as it is. - Use the result: Copy result or Download it. Use result as input feeds it back in (for example to decode a string that was stringified twice) and the last button switches direction, so you can check that the result decodes back to what you started with.
How it works
“Stringifying” here means turning text into a string literal: the text is wrapped in quotes and every character that cannot appear as it is gets a backslash escape, so the result can be placed inside code or inside another JSON value. It is what you get from JSON.stringify(text) in JavaScript, and when the text is itself JSON it is the “second” stringify, JSON.stringify(JSON.stringify(object)).
- Checking: JSON input is validated by the browser’s own parser. If it is invalid, the tool finds the first mistake and shows its line and column with a short explanation.
- Minifying without touching numbers: the tool does not parse and re-write your data. It removes whitespace that sits outside strings and leaves everything else as typed, so a number such as
12345678901234567890keeps every digit (parsing it in JavaScript would turn it into 12345678901234567000). - JavaScript-style objects are read by a small built-in reader, never run as code. Single and double quoted strings, keys without quotes,
//and/* */comments, trailing commas and numbers such as.5,+3or0xFFare converted to strict JSON. Values that JSON does not have (undefined,NaN,Infinity) are reported as errors. - Escaping:
"becomes\"(or'becomes\'in a single-quoted string),\becomes\\, and line breaks, tabs, backspace and form feed become\n,\t,\b,\fand\r. Other control characters, the delete character and the two JavaScript line separators (U+2028 and U+2029) are written as\uXXXX, and a lone half of a surrogate pair is escaped too, so the result is always valid. Characters above 127 are written as\uXXXXonly if you ask for ASCII output. - Unstringifying reads the escapes back:
\" \' \\ \/ \b \f \n \r \t \v \0 \xHH \uHHHH \u{H...}, and joins surrogate pairs. An unknown escape (for example the\Uin"C:\Users") is reported with its position instead of being guessed.
Nothing you enter is sent anywhere or saved; the page works offline once loaded.
Worked example
1. JSON to a string. The JSON {"name":"Ann","tags":["a","b"]} becomes the JSON string"{\"name\":\"Ann\",\"tags\":[\"a\",\"b\"]}"
Each inner quote now has a backslash. Pretty-printed input gives the same result with “Minify JSON first” ticked; unticked, the line breaks and spaces are kept and written as \n and spaces.
2. A JavaScript-style object. {name: 'Ann', tags: ['a','b',], /* note */ } is converted to {"name":"Ann","tags":["a","b"]} and gives the same string as in example 1.
3. Plain text. The two lines He said "hi" and bye become "He said \"hi\"\nbye": the quotes are escaped and the line break is written as \n.
4. A long number. {"id": 12345678901234567890, "ok": true} becomes "{\"id\":12345678901234567890,\"ok\":true}", with every digit of the id kept.
5. ASCII output. The text café € 😀 with “Escape non-English characters” becomes "caf\u00e9 \u20ac \ud83d\ude00"; the emoji is written as a surrogate pair.
6. A JavaScript string. The text It's "ok" written as a JavaScript string is 'It\'s "ok"'; only the single quote needs a backslash.
7. Back again. Unstringify turns "{\"a\":[1,2]}" into the JSON text {"a":[1,2]} and, with pretty-printing, into four indented lines. A Windows path written as "C:\Users" is reported as an error at the \U; written "C:\\Users" it decodes to C:\Users.
Quick reference
| You see | It stands for |
|---|---|
\" | a double quote |
\' | a single quote (needed only inside a single-quoted string) |
\\ | a backslash |
\/ | a forward slash (optional; used for HTML safety) |
\n, \r, \t | line feed, carriage return, tab |
\b, \f | backspace, form feed |
\v, \0 | vertical tab, null (read when unstringifying; JSON itself does not use them) |
\u00e9 | the character with that 4-digit hexadecimal code (here é) |
\ud83d\ude00 | a character above U+FFFF written as two halves (here a smiling face) |
\xE9, \u{1F600} | JavaScript forms, read when unstringifying |
| Output format | Example for It's "ok" |
|---|---|
| JSON string (double quotes) | "It's \"ok\"" |
| JavaScript string (single quotes) | 'It\'s "ok"' |
| Escaped text only | It's \"ok\" |
| Limit | Value |
|---|---|
| Input size | Up to 20 million characters (file or typed) |
| Nesting depth | 1,000 levels |
| Result box | Shows the first 400,000 characters; Copy and Download always include everything |
When you need this
- JSON inside JSON: put a JSON document into a string field of another document, as many APIs and message queues expect.
- Code and tests: paste a payload into a JavaScript, Java or other source file as a string constant, without escaping every quote by hand.
- Config and environment values: store a JSON value on a single line in a
.envfile, a CI setting or a YAML value. - Reading logs: unstringify an escaped payload copied from a log or a database field to see the real text.
- HTML pages: embed data in a script tag with the HTML-safe option so it cannot close the tag early.
- Cleaning up JavaScript objects: turn a pasted object literal into strict JSON first.