What JSON Stringify Online does
JSON Stringify turns a JSON document into a single escaped string literal, the same result as calling JSON.stringify twice. Use it when JSON has to be stored as a string inside another JSON document, an environment variable or source code.
JSON Stringify Online examples
The built-in sample
Input
{"name":"Ada Lovelace","active":true,"tags":["math","code"],"address":{"city":"London"}}Output
"{\"name\":\"Ada Lovelace\",\"active\":true,\"tags\":[\"math\",\"code\"],\"address\":{\"city\":\"London\"}}"This is the input that the Load sample button fills in.
Quotes, backslashes and line breaks
Input
{"msg":"He said \"hi\"\n","dir":"C:\\temp","city":"Zürich"}Output
"{\"msg\":\"He said \\\"hi\\\"\\n\",\"dir\":\"C:\\\\temp\",\"city\":\"Zürich\"}"Every quote and backslash gains another backslash, so \" becomes \\\" and \n becomes \\n. Non-ASCII characters such as ü are left as they are.
Each output was produced by running this tool on the input above it.
How it works
The input is parsed to make sure it is valid JSON, minified, and then serialised again as a string, which escapes every double quote as \" and every backslash as \\. The output, including its surrounding quotes, is a valid JSON string value.
Details and limits
- The input is minified before it is escaped, so indentation in what you paste never ends up inside the string.
- To go back, paste the string into String to JSON.
- The result is also a valid string literal in JavaScript, Java, C#, Go and Python source code, because all of them accept the escapes JSON uses.
- Input that is not valid JSON stops the tool, and the status line shows where the problem is. The JSON Validator page lists the usual causes.
Questions
When do I need JSON inside a string?
When a field that carries JSON is itself typed as a string: a message body in a queue, a "payload" column, an environment variable, or a JSON document embedded in another one.