Shopping Cart

[How to] JSON with FiveM – Server Tutorials


So, when I was learning JSON with FiveM I couldn’t find any tutorials on how to use it, so here we go.

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)

If you have any tips, or see a mistake please comment bellow and ill sort it out.



Premium ESX Scripts? Click here!

Leave a Reply
FiveM ESX Scripts

The best scripts and maps

Best support

Problems? We are there to help!

Wide range of products

We have a wide range of products

100% Secure Checkout

Easy and encrypted