Type Function Library json.* Return value Table Revision Release 2024.3703 Keywords json See also json.decode()
Decodes the contents of a file that is expected to contain nil
, the position of the next character that doesn't belong to the object, and an error message. Errors can either relate to issues opening the file or to JSON syntax issues.
The filename
parameter should usually be obtained from system.pathForFile()
so it can be correctly located in the application's sandbox. See the Example below.
json.decodeFile( filename [, position [, nullval]] )
String. String containing the name of a file containing JSON data.
Number. Index within file to start decoding (default is 1
if omitted).
Value to be returned for items with a value of json.null
nil
don't normally exist).
local json = require( "json" ) local filename = system.pathForFile( "datafile.json", system.ResourceDirectory ) local decoded, pos, msg = json.decodeFile( filename ) if not decoded then print( "Decode failed at "..tostring(pos)..": "..tostring(msg) ) else print( "File successfully decoded!" ) end