Using JSON in FiveM
JSON is how simple data survives a server restart without setting up a database. Many scripts use it for config files, settings, whitelists, and temporary storage. This lesson teaches you to save, load, and update JSON files - the lightweight way to give your resource a memory.
Build it
Create the resource
resources/qu_json_demo/
fxmanifest.lua
server.lua
fx_version 'cerulean'
game 'gta5'
server_script 'server.lua'
Save data to JSON
-- Create a Lua table with player data
local playerData = {
name = "John",
money = 5000,
job = "police"
}
-- Convert to JSON and save to a file
SaveResourceFile(
GetCurrentResourceName(), -- which resource owns this file
"playerdata.json", -- the filename
json.encode(playerData), -- convert table → JSON text
-1 -- length: -1 means "all of it"
)
print("Data saved to playerdata.json")