Syntax
json.escape(text: string): stringArguments
| Name | Type | Description |
|---|---|---|
text | string | String to escape. The function reads this argument with string type checking. |
Returns
| Name | Type | Description |
|---|---|---|
escaped | string | Escaped JSON string content without the opening and closing quote. Quotes, backslashes, common control characters, and bytes below 0x20 are escaped. |
Description
Escapes a string using Real's JSON string escaping rules and returns the escaped content without surrounding quotes.
Call it with 1 parameter(s): text. The argument table explains which values are required and which ones only refine the behavior.
It returns escaped (string). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Escape a string for the inside of a JSON string without adding the surrounding quotes.
local source = "line 1" .. string.char(10) .. [[line "2"]]
local escaped = json.escape(source)
print(escaped)