Jump to content

RageMP Client Side load JSON file


ffpgmbh

Recommended Posts

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 by ffpgmbh
Corrected mistake from typing file names from head
Link to comment
Share on other sites

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 by ffpgmbh
Link to comment
Share on other sites

// 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...