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.
Luau
json.decode(text: string, options: JsonDecodeOptions?) -> JsonValue?Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | Complete JSON document to parse. |
options | JsonDecodeOptions? | Optional boolean useNull flag or options table. Null preservation is enabled by default; maxDepth defaults to 256. |
Argument fields
Luau
JsonDecodeOptions = boolean | {useNull: boolean?, maxDepth: number?}| Field | Description |
|---|---|
useNull | Defaults 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. |
maxDepth | Maximum 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.
Luau
JsonValue = string | number | boolean | JsonNull | {JsonValue} | {[string]: JsonValue}Luau
JsonNull = typeof(json.null)Usage notes
Malformed JSON raises an error. maxDepth is clamped to the range 1–4096.
Example
Luau
local settings = json.decode('{"theme":"dark","scale":1.25}')
print(settings.theme, settings.scale)