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. json.encodePretty reads the same options as json.encode, then forces pretty to true. Without options, it uses a two-space indent. A number sets the indent width clamped to 0.16, a string sets the indent text, and a table can set sortKeys, emptyTableAsArray, errorOnUnsupported, encodeInvalidNumbersAsNull, maxDepth, and indent.

Returns

string
Readable formatted JSON string. Encoding errors are thrown as Luau errors.

Types

EncodeOptions

Controls JSON serialization and formatting.

Example

Encode JSON-compatible values as readable formatted JSON with pretty output forced on.