Skip to main content

sm.json

The JSON library is used for reading and writing data from/to JSON files.

Functions

fileExists

sm.json.fileExists( file )

Returns whether any file or folder exists at the given path.

Arguments:
  • file [ string ]: The file path to check.
Returns:
  • [ bool ]: Whether the file exists or not.

open

sm.json.open( file )

Opens a JSON file and returns it's content as a Lua table.

Arguments:
  • file [ string ]: The file path.
Returns:
  • [ table ]: The loaded JSON data.

parseJsonString

sm.json.parseJsonString( json )

Parses a JSON string and returns it as a Lua table.

Arguments:
  • file [ string ]: The JSON string.
Returns:
  • [ table ]: The parsed JSON data.

save

sm.json.save( data, path )

Writes a Lua table to a JSON file.

If the file does not exist, this will create a new file at the given file path.
If the file does exist, this will overwrite the file content.

Arguments:
  • data [ table ]: The Lua table.
  • path [ string ]: The path to the JSON file.

writeJsonString

sm.json.writeJsonString( data )

Converts a Lua table to a JSON string.

Arguments:
  • data [ table ]: The Lua table.
Returns:
  • [ string ]: The JSON string.