json.decode Synchronous

  • json.parse

Parse JSON text into Luau values. Use json.decodeSafe when a malformed document should return an error result instead of raising. Use it to load settings or interpret an HTTP response body. Parsing checks JSON syntax; check the resulting value and required fields before using them.

Syntax
Luau
json.decode(text: string, options: JsonDecodeOptions?) -> JsonValue?

Parameters

Function parameters
ParameterTypeDescription
textstringComplete JSON document to parse.
optionsJsonDecodeOptions?Optional boolean useNull flag or options table. Null preservation is enabled by default; maxDepth defaults to 256.

Argument fields

JsonDecodeOptions fields
Luau
JsonDecodeOptions = boolean | {useNull: boolean?, maxDepth: number?}
FieldDescription
useNullDefaults to true, preserving JSON null as json.null. false converts null to nil, which can remove table entries. A boolean options argument is shorthand for this field.
maxDepthMaximum nesting depth. Defaults to 256; an integer is required and is clamped to 1–4096.

Returns

JsonValue?

The decoded value. JSON null becomes json.null by default; disabling useNull can instead produce nil or holes in arrays.

JsonValue fields
Luau
JsonValue = string | number | boolean | JsonNull | {JsonValue} | {[string]: JsonValue}
JsonNull fields
Luau
JsonNull = typeof(json.null)

Usage notes

Malformed JSON raises an error. maxDepth is clamped to the range 1–4096.

Example

Example
Luau
local settings = json.decode('{"theme":"dark","scale":1.25}')
print(settings.theme, settings.scale)
Kawaii documentation