Syntax
json.unescape(text: string): stringArguments
| Name | Type | Description |
|---|---|---|
text | string | Escaped JSON string content, or a complete quoted JSON string literal whose first and last bytes are quotes. The function reads this argument with string type checking. |
Returns
| Name | Type | Description |
|---|---|---|
text | string | Decoded string. Supported escapes include \", \\, \/, \b, \f, \n, \r, \t, and \uXXXX with surrogate-pair handling. Invalid escapes, unescaped control characters, unterminated strings, and trailing characters after a quoted literal throw a Luau error with a near-position suffix. |
Description
Decodes JSON string escape sequences from escaped string content or from a complete quoted JSON string literal. The input is parsed with the JSON string parser, not as a full JSON document.
Call it with 1 parameter(s): text. The argument table explains which values are required and which ones only refine the behavior.
It returns text (string). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Decode JSON string escapes from escaped content or a quoted JSON string literal.
local escaped = json.escape("Real Docs" .. string.char(10) .. "Docs")
local restored = json.unescape(escaped)
print(restored)