So, after I was studying JSON with FiveM I couldn’t discover any tutorials on find out how to use it, so right here we go.


Inserting an array right into a JSON file

native loadFile= LoadResourceFile(GetCurrentResourceName(), "./fileNameHere.json")
native data = {title = "w00pi the legend", age = 17, coolness = 1000}

SaveResourceFile(GetCurrentResourceName(), "fileNameHere.json", json.encode(data), -1)

^^
That can insert the array into the json file leaving the data array within the JSON file trying like this.

{"title" : "w00pi the legend", "age" : 17, "coolness" : 1000}

How one can extract JSON data

native loadFile= LoadResourceFile(GetCurrentResourceName(), "./fileNameHere.json") -- you solely have to do that as soon as in your code, i simply put it in because it wont get complicated.
native extract = {}
extract = json.decode(loadFile)
SaveResourceFile(GetCurrentResourceName(), "fileNameHere.json", json.encode(extract), -1)

When you’ve got any ideas, or see a mistake please remark bellow and ailing kind it out.

Thanks!



Looking for a FiveM Server host? Click here