json. decode Synchronous
json.parse
Parse a complete JSON document into Luau values. Use it after reading a settings file or response body whose syntax you expect to be valid.
Luau
json.decode(text: string, options: JsonDecodeOptions?) -> JsonValue?Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | Complete JSON document. |
options | JsonDecodeOptions? | Optional useNull boolean or options table. By default null becomes json.null and maxDepth is 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 is json.null by default; with useNull=false it becomes nil.
Luau
JsonValue = string | number | boolean | JsonNull | {JsonValue} | {[string]: JsonValue}Luau
JsonNull = typeof(json.null)Usage notes
Malformed JSON raises an error. The parser checks syntax, not whether your application’s required keys and types are present.
maxDepth is clamped to 1 through 4096.
Example
Luau
local settings = json.decode('{"theme":"dark","scale":1.25}')
if json.isObject(settings) and type(settings.theme) == "string" then
print(settings.theme)
end