ffpgmbh Posted August 19, 2019 Share Posted August 19, 2019 (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, 2019 by ffpgmbh Corrected mistake from typing file names from head Link to comment Share on other sites More sharing options...
MiMIMi Posted August 19, 2019 Share Posted August 19, 2019 Is the json file in client_packages folder? Link to comment Share on other sites More sharing options...
ffpgmbh Posted August 19, 2019 Author Share Posted August 19, 2019 The JSON file is in the subfolder represented by [...] of the client_packages folder. Link to comment Share on other sites More sharing options...
Captien Posted August 19, 2019 Share Posted August 19, 2019 You have to either change your json into exported object in a js file or use require('package://[...]/vehicles.json'); More Info here Link to comment Share on other sites More sharing options...
ffpgmbh Posted August 19, 2019 Author Share Posted August 19, 2019 (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, 2019 by ffpgmbh Link to comment Share on other sites More sharing options...
tokyoghoul Posted August 19, 2019 Share Posted August 19, 2019 Use .js Link to comment Share on other sites More sharing options...
MrCarter Posted August 20, 2019 Share Posted August 20, 2019 // 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; }); Link to comment Share on other sites More sharing options...
ffpgmbh Posted August 23, 2019 Author Share Posted August 23, 2019 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now