JSON

json.unescape

Decodes JSON string escape sequences from escaped string content or from a complete quoted JSON string literal.

Syntax

json.unescape(text: string): string

Arguments

NameTypeDescription
textstringEscaped 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

NameTypeDescription
textstringDecoded 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)