Output will appear here
Output will appear here
To convert JSON to a string, paste it on the left. You get one escaped string literal: every " becomes \", every backslash is doubled and line breaks become \n. Valid JSON is minified first, so the result matches JSON.stringify(JSON.stringify(obj)). Switch to String to JSON to go the other way and turn a stringified payload back into a readable object.
By Ankit Aglawe · Updated · Runs entirely in your browser
The outer layer of quotes is added, every inner quote is escaped, and escapes that were already in the JSON get escaped again: \n inside bio becomes \\n. The indentation is gone because the JSON was minified first.
{
"name": "Ada \"The Countess\"",
"path": "C:\\Users\\ada",
"bio": "line one\nline two",
"tags": ["math", "code"]
}"{\"name\":\"Ada \\\"The Countess\\\"\",\"path\":\"C:\\\\Users\\\\ada\",\"bio\":\"line one\\nline two\",\"tags\":[\"math\",\"code\"]}"This is the String to JSON direction, the "json to object converter" case. The literal is parsed and pretty-printed. Note that meta stays a string: it is JSON inside a string field, and only the outer value is unwrapped. Paste the meta value on its own to decode it too.
"{\"event\":\"invoice.paid\",\"data\":{\"id\":\"in_42\",\"amount\":1999,\"meta\":\"{\\\"plan\\\":\\\"pro\\\"}\"}}"{
"event": "invoice.paid",
"data": {
"id": "in_42",
"amount": 1999,
"meta": "{\"plan\":\"pro\"}"
}
}Logs and message queues often stringify a payload that is already a string, giving "\"{\\\"id\\\":1}\"". String to JSON keeps unwrapping (up to five levels) until it reaches an object, array or plain text.
In JSON to String mode, text that does not parse is still escaped, as plain text, and a note says so. That is useful for putting a multi-line message into a JSON field, but it also means a typo in your JSON will not stop the conversion. Check for the note.
Untick Minify first to escape the JSON exactly as typed. The indentation and newlines then survive as \n and spaces inside the string, which is what you want for a pretty-printed fixture and not what you want for an environment variable.
Non-ASCII text such as café or emoji is kept as-is, which is valid JSON. Control characters below U+0020 are escaped as \u0001 and so on. U+2028 and U+2029 are left raw, which has been legal in JavaScript string literals since ES2019.
String to JSON accepts the literal with or without its surrounding quotes, so {\"id\":1} copied out of a log line works as well as "{\"id\":1}". An unescaped " in the middle is reported as an error rather than guessed at.
Minifying parses the JSON, and JavaScript numbers lose precision above 2^53. An id like 9007199254740993 would come out as 9007199254740992. Untick Minify first and the original digits are kept, because the text is escaped without being parsed.
| Character | In the string | Why |
|---|---|---|
" double quote | \" | Would end the string |
\ backslash | \\ | Starts an escape |
| newline | \n | Raw line breaks are not allowed in JSON strings |
| tab | \t | Control character |
| carriage return | \r | Control character |
| other U+0000 to U+001F | \u00XX | Control characters must be escaped |
/ forward slash | / | Allowed raw; escaping it is optional |
| non-ASCII (é, 中, emoji) | unchanged | JSON text is Unicode |
In JSON to String mode, paste any JSON. Valid JSON is minified first (untick Minify first to keep its line breaks). Text that is not JSON is escaped as-is.
Paste a string literal, with or without its outer quotes. Escapes are resolved and, if the result is JSON, it is pretty-printed. Double-stringified values are unwrapped too.
Copy the escaped string into code, an environment variable, a log line or a JSON field that expects a string.
Paste the JSON into the left pane in JSON to String mode. The right pane shows one escaped string literal you can paste into code, an environment variable or a JSON field. In JavaScript the same thing is JSON.stringify(JSON.stringify(obj)), or JSON.stringify(obj) if you only need the JSON text.
Switch to String to JSON and paste the string. The tool resolves the escapes, unwraps double-stringified values and pretty-prints the result. In code, use JSON.parse(str), and call it again if the result is still a string.
JSON.stringify on an object produces JSON text. Escaping takes text, JSON or not, and makes it safe to put inside a JSON string by adding quotes and backslashes. Turning JSON into a string literal is both steps, which is what this tool does.
Because the JSON had line breaks or a value contained an escaped newline. With Minify first ticked, formatting newlines are removed before escaping, so any \n left was part of a value.
Stringify it with Minify first ticked so it is a single line, then wrap it in single quotes in a shell or .env file. Read it back with JSON.parse(process.env.MY_VAR).
No. Both directions run in your browser with the built-in JSON functions. Nothing is sent anywhere, so API keys inside a payload stay on your machine.
Need several formats at once? Convert All shows every output from one paste. Or browse all JSON converters.