ffpgmbh 0 Posted August 19 (edited) Hello RageMP Community, I am having a hard time figuring out how to load a JSON file into the Client side to generate a menu. When I do this: var vehicles = require("./[...]/vehicleshops.json"); and restart and join the Server the Error message says that the file "./[...]/vehicleshops.json.js" could not be found. I have also tried import vehicles from ("./[...]/vehicleshops.json") With this attempt it has a problem with the overall Syntax, so it doesn't work either. What is the correct way of loading a JSON file client side, or is there even a working way? Kind regards, ffpgmbh / Fionn Edited August 19 by ffpgmbh Corrected mistake from typing file names from head Share this post Link to post Share on other sites
MiMIMi 2 Posted August 19 Is the json file in client_packages folder? Share this post Link to post Share on other sites
ffpgmbh 0 Posted August 19 The JSON file is in the subfolder represented by [...] of the client_packages folder. Share this post Link to post Share on other sites
Captien 134 Posted August 19 You have to either change your json into exported object in a js file or use require('package://[...]/vehicles.json'); More Info here Share this post Link to post Share on other sites
ffpgmbh 0 Posted August 19 (edited) I really appreciate your attempt to help, but when connecting to the server the client says that the file "D:\RageMP\client_packages\[...]\package://[...]/vehicleshops.json.js" could not be found. What really makes me wonder, is the fact that it looks for a .js file although iI am requesting a .json file. My code is now var vehicleConfig = require("package://[...]/vehicleshops.json"); the file vehicleshops.json is present in the downloaded folder, I just double-checked. Edited August 19 by ffpgmbh Share this post Link to post Share on other sites
MrCarter 11 Posted August 20 // shops.js exports.vehicle = [{"name":"Whatever"}, // etc.]; exports.market = [{"name":"Whatever2"}, // etc.]; // Other clientside file: const Shops = require('path/to/shops.js'); Shops.vehicle.forEach((shop, idx, arr) => { // shop.name; }); Share this post Link to post Share on other sites
ffpgmbh 0 Posted August 23 Thanks to all of you. My final Solution is to just paste my whole json file into a json to js literal converter and paste it into the exports part of a js file, just like MrCarter suggested. Share this post Link to post Share on other sites