JSON String Escaper
Produce a valid JSON string literal.
Read the guideRun the tool
The calculation runs in your browser. This tool does not send your input to JVR Software.
More information
Back to the toolWhat it is and when to use it
JSON Escape creates a JSON string literal from arbitrary text. Use it when a sample value contains quotes, backslashes, tabs or line breaks and you want to paste it into a configuration example or test fixture without having to escape each character by hand.
How it works
The browser serialises the input as a single JSON string. It adds outer quotation marks and places escapes where JSON syntax requires them. The backslash characters visible in the serialized result are instructions to a JSON parser. The parser restores the original text value.
How to use it
- Paste the original characters exactly as you want them decoded.
- Copy the complete result, including the outer double quotes, where a JSON value is expected.
- Validate the resulting full document through JSON Formatter before you put it into configuration or share the fixture.
Worked example
Typing two lines, Hello and World, produces a JSON string containing Hello followed by an escaped newline and World. If the input instead includes the actual two characters backslash and n, the backslash is escaped so a later parser returns those two characters.
Reading the result
The output is a literal representing one string, even if the original input looks like a number, array or object. A stringifying application may escape the result a second time if you pass it as a raw string. In that case pass the original text to its serializer.
Common mistakes and limits
JSON syntax is separate from the syntax of a shell command or an HTML script element. Pass values through the correct serializer for each boundary. Build objects and arrays as data in your application when possible, with this tool providing a transparent way to check what special characters do.
