Syntax
json.escape(text: string): stringArguments
| Name | Type | Description |
|---|---|---|
text | string | Text value used by the operation. |
Returns
| Name | Type | Description |
|---|---|---|
escaped | string | Escaped JSON string content. |
Description
Escapes text so it can safely appear inside a JSON string literal.
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 text for use inside a JSON string.
local source = "line 1" .. string.char(10) .. "line 2"
local escaped = json.escape(source)
print(escaped)