Skip to content

smelt.json

Availability: Everywhere, including headless mode.

Encode/decode JSON for Lua plugins. Tables with contiguous 1..N integer keys encode as arrays; other tables encode as objects. Use smelt.json.array() when an empty table must encode as an array.

smelt.json.array

fun(): table

Create an empty JSON array table. Unlike {}, it encodes as [] while empty.

smelt.json.decode

fun(text: string): any, string?

Decode JSON into a Lua value. Returns (value, nil) on success or (nil, err_string) on failure.

smelt.json.encode

fun(value: any, opts: table?): string

Encode a Lua value as JSON. Pass { pretty = true } to format with indentation. Tables with contiguous 1..N integer keys encode as arrays; other tables encode as objects. Use smelt.json.array() for an empty array. Raises an error for cycles, nesting deeper than 128 levels, functions and other non-data values, non-finite numbers, and strings that are not valid UTF-8.