Syntax
json.parse(json: string, options?: DecodeOptions): anyArguments
| Name | Type | Description |
|---|---|---|
json | string | JSON string to parse. The function reads this argument with string type checking. |
options? | DecodeOptions | Optional decode options. A boolean sets useNull. A table can set useNull and maxDepth. |
Returns
| Name | Type | Description |
|---|---|---|
decoded | any | Decoded value. JSON objects and arrays become tables with JSON type markers, strings become Lua strings, numbers become Lua numbers, booleans become booleans, and null becomes json.null unless useNull is false. |
Description
Parses a JSON string like json.decode.
Call it with 2 parameter(s): json, options. The argument table explains which values are required and which ones only refine the behavior.
It returns decoded (any). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Parse JSON with the same parsing behavior as json.decode.
local settings = json.parse('{"volume":0.75,"theme":"dark","missing":null}', {
useNull = true,
})
print(settings.volume)
print(settings.theme)
print(json.isNull(settings.missing))Types
DecodeOptions
Controls JSON parsing behavior.
useNull? boolean Represents JSON null with the library's null sentinel instead of nil.maxDepth? integer Sets the maximum nesting depth, clamped from 1 to 4096.