convertCASEpro

MODE

JSON Stringify Text

Paste text, get a string literal that is safe to place inside JSON.

INPUT
CHARS: 0WORDS: 0LINES: 0
OUTPUT
CHARS: 0WORDS: 0LINES: 0

How the JSON Stringify Text works

The tool applies the same escaping as JSON.stringify: double quotes become backslash quote, line breaks become the two characters backslash n, tabs and control characters are escaped, and backslashes are doubled. The result can be pasted inside a JSON document as a value.

Optional switches wrap the result in double quotes, escape every non-ASCII character as a backslash u sequence for systems that need pure ASCII, or stringify twice for JSON that has to be embedded inside another JSON string.

When it is useful

  • •Putting a block of HTML, SQL or code into a JSON field.
  • •Preparing a message body for a REST API request.
  • •Building test fixtures that contain multi line text.
  • •Embedding one JSON document inside another.

Frequently Asked Questions

How do I reverse the process?

Use the JSON Unstringifier, which turns an escaped string back into the original text.

Why would I stringify twice?

Some APIs expect a JSON string whose content is itself JSON. The first pass makes the inner document a string, the second makes that safe to embed in an outer document.

Are emoji escaped?

Only if the ASCII option is on. Then they become surrogate pairs, such as backslash uD83D backslash uDE00.

Related tools

[ Browse all tools ]