Skip to content
Test versionSearch

Developer tools

One JSON string literal: encode and decode

Encode text as a single JSON string literal with escaped quotes and backslashes, or decode one JSON string value back to plain text.

How it worksFAQRelated tools

Content reviewed:

The example values can be changed. Press Calculate to update the result; you can download it as TXT or CSV and collect scenarios in this tab. Nothing is saved or sent automatically.

Uses the browser’s JSON.stringify and JSON.parse, so quotes, backslashes and line breaks are escaped exactly as JSON requires. Decoding accepts a single JSON string only, not objects or code. The result is safe inside JSON, but not automatically inside HTML or a <script> tag. Text to encode may have up to 400 characters, text to decode up to 500; a result longer than 500 characters is refused. Control characters are not accepted. You can also load a one-line UTF-8 file of up to 32 KiB. Downloads: TXT, CSV (lines that look like formulas are protected for spreadsheets), JSON and printable HTML. Nothing is saved or sent automatically.

Decimal results are approximate. Inputs stay in this browser tab.

How it works

Text is converted with the browser’s standard functions (UTF-8 encoder, JSON, String.normalize) or the RFC 4648 Base32 alphabet. Each direction is checked strictly, so invalid input is refused instead of guessed. Uses the browser’s JSON.stringify and JSON.parse, so quotes, backslashes and line breaks are escaped exactly as JSON requires. Decoding accepts a single JSON string only, not objects or code. The result is safe inside JSON, but not automatically inside HTML or a <script> tag. Text to encode may have up to 400 characters, text to decode up to 500; a result longer than 500 characters is refused. Control characters are not accepted. You can also load a one-line UTF-8 file of up to 32 KiB. Downloads: TXT, CSV (lines that look like formulas are protected for spreadsheets), JSON and printable HTML. Nothing is saved or sent automatically.

Worked example

With these example values the calculator gives the result below. You can change any value in the form above.

Inputs

Direction
Encode
Text or one quoted JSON string
Own "ä" \ 🚀

Result

Encoded result
"Own \"ä\" \\ 🚀"
Result code points
11
Result UTF-16 units
12

Frequently asked questions

How do I escape a string for JSON?

Choose encode and enter the text. The JSON string tool returns a double-quoted JSON string literal with quotes and backslashes escaped, using the standard JSON.stringify function.

How do I decode a JSON string literal?

Choose decode and paste exactly one JSON string value, including its quotes. The tool uses JSON.parse and requires the result to be a string, so objects and other values are refused.

How long can the text be in the JSON string encoder?

Text to encode can have at most 400 UTF-16 units and a JSON string to decode at most 500. Each output is limited to 500 characters, and longer expansions are refused.

Can I load a file into the JSON string tool?

Yes, an optional UTF-8 file of up to 32 KiB and 500 UTF-16 units, as one line without line endings. Encoding stays limited to 400 units.

Are control characters allowed in a JSON string here?

No. The JSON string literal tool refuses control characters and unpaired surrogates, both in the raw text and in decoded text.

Is an encoded JSON string safe to embed in HTML?

Not by itself. The result is specifically a JSON string literal, not a general language literal, and the result alone is not safe embedding in HTML or script tags.

Does the JSON string tool evaluate code?

No. It handles only one string value and performs no object handling, expression evaluation or code evaluation.