Page 1 of 1

JSON with FiveM

Posted: Wed Feb 25, 2026 8:09 pm
by greenie
Inserting an array into a JSON file

local loadFile= LoadResourceFile(GetCurrentResourceName(), "./fileNameHere.json")
local information = {name = "w00pi the legend", age = 17, coolness = 1000}

SaveResourceFile(GetCurrentResourceName(), "fileNameHere.json", json.encode(information), -1)
^^
That will insert the array into the json file leaving the information array in the JSON file looking like this.

{"name" : "w00pi the legend", "age" : 17, "coolness" : 1000}
How to extract JSON information

local loadFile= LoadResourceFile(GetCurrentResourceName(), "./fileNameHere.json") -- you only have to do this once in your code, i just put it in since it wont get confusing.
local extract = {}
extract = json.decode(loadFile)
SaveResourceFile(GetCurrentResourceName(), "fileNameHere.json", json.encode(extract), -1)