Skip to main content

Arguments

any
required
Value to encode. nil, booleans, numbers, strings, tables, and json.null are handled directly. Unsupported Lua types encode as null unless errorOnUnsupported is true.
EncodeOptions
Optional encode options. A boolean toggles pretty output. A number enables pretty output with that many spaces clamped to 0.16. A string enables pretty output with that indent. A table can set pretty, sortKeys, emptyTableAsArray, errorOnUnsupported, encodeInvalidNumbersAsNull, maxDepth, and indent.

Returns

string
Encoded JSON string. Encoding errors are thrown as Luau errors.

Types

EncodeOptions

Controls JSON serialization and formatting.

Example

Encode JSON-compatible values, using json.array when an empty array must stay an array.