Available since Version 1.1.
Decodes a JSON string into a Lua value. JSON objects and arrays are returned as tables. JSON arrays use sequential integer keys starting at 1. Returns nil if the input string is empty or whitespace.
Syntax
JSON.Decode( json )Arguments
- json (string): The JSON string to decode.
Return Values
- (table | string | number | boolean |
nil): The decoded Lua value, ornilif the input is empty or whitespace.
Examples
local result = JSON.Decode('{"name":"Homer","level":1}')
print(result.name) -- Outputs: Homer
print(result.level) -- Outputs: 1local result = JSON.Decode('["a","b","c"]')
print(result[1]) -- Outputs: a
print(result[2]) -- Outputs: b