JSON

json.quote

Wraps and escapes text as a complete JSON string literal.

Syntax

json.quote(text: string): string

Arguments

NameTypeDescription
textstringText value used by the operation.

Returns

NameTypeDescription
quotedstringComplete JSON string literal.

Description

Wraps and escapes text as a complete 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 quoted (string). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Convert plain text into a complete quoted JSON string.

local source = "Real Docs" .. string.char(10) .. "Documentation"
local quoted = json.quote(source)

print(quoted)