Loading JSON files from sub directories not working?

I have been able to load a json file from the root directory of my resource but not in subdirectories, am I doing something wrong?
fxmanifest.lua

files {
    'data/ls_custom/mods.json',
}

other.lua

-- This would work
-- local loadFile = LoadResourceFile(GetCurrentResourceName(), "mods.json") 
local loadFile = LoadResourceFile(GetCurrentResourceName(), "data/ls_custom/mods.json")
local extract = {}
extract = json.decode(loadFile)

LS.mods = extract

I’ve used the following link to get the basics working: [How to] JSON with FiveM

Maybe you need to write your directory like that : ./data/ls_custom/mods.json".

I attempted that but with no success. Both in fxmanifest and the other file.

do you get an error for this variable? Seems like LS is non existent.

try adding this to the top

LS = {};  

There’s no problem with my code. LoadResourceFile returns nil. There’s most definitely a problem with the file path since just using “mods.json” and having the file be at the root of resource allows for it to work.

Have you tried to change the name of the file? To see if that messes up your data? As well as do you have any bad characters for the resource itself?

Thanks for your answer though the JSON is valid, I’ve checked it with an online JSON verifier as well as a normal browser console.

Also, LoadResourceFile returns a string, which it’s able to do when I put the file in the root of my resource.
So if it return nil that must mean it’s unable to find the file, I’m just unable to verify how I’m supposed to form the path correctly for sub directories. My path is correct following normal standards on relative paths.

If you want to check yourself, here’s the JSON I’m trying to load.

[
    {
        "name": "Armor",
        "type": "normal",
        "mod": 16,
        "start_cost": 5000,
        "increment": 5000,
        "labels": [
            "Armor Upgrade 20%",
            "Armor Upgrade 40%",
            "Armor Upgrade 60%",
            "Armor Upgrade 80%",
            "Armor Upgrade 100%"
        ]
    },
    {
        "name": "Brakes",
        "type": "normal",
        "mod": 12,
        "start_cost": 300,
        "increment": 300,
        "labels": [
            "Semi-metallic Brakes",
            "Ceramic Brakes",
            "Carbon Brakes"
        ]
    },
    {
        "name": "Bumpers",
        "options": [
            {
                "name": "Front Bumper",
                "type": "normal",
                "mod": 1,
                "start_cost": 1000
            },
            {
                "name": "Rear Bumper",
                "type": "normal",
                "mod": 2,
                "start_cost": 1000
            }
        ]
    },
    {
        "name": "Engine",
        "type": "normal",
        "mod": 11,
        "start_cost": 10000,
        "increment": 10000,
        "labels": [
            "EMS Upgrade Level 1",
            "EMS Upgrade Level 2",
            "EMS Upgrade Level 3",
            "EMS Upgrade Level 4"
        ]
    },
    {
        "name": "Exhaust",
        "type": "normal",
        "mod": 4,
        "start_cost": 1000
    },
    {
        "name": "Grille",
        "type": "normal",
        "mod": 6,
        "start_cost": 1000
    },
    {
        "name": "Hood",
        "type": "normal",
        "mod": 7,
        "start_cost": 2000
    },
    {
        "name": "Horn",
        "type": "normal",
        "mod": 14,
        "start_cost": 250,
        "labels": [
            "Truck Horn",
            "Police Horn",
            "Clown Horn",
            "Musical Horn 1",
            "Musical Horn 2",
            "Musical Horn 3",
            "Musical Horn 4",
            "Musical Horn 5",
            "Sadtrombone Horn",
            "Classical Horn 1",
            "Classical Horn 2",
            "Classical Horn 3",
            "Classical Horn 4",
            "Classical Horn 5",
            "Classical Horn 6",
            "Classical Horn 7",
            "Scaledo Horn",
            "Scalere Horn",
            "Scalemi Horn",
            "Scalefa Horn",
            "Scalesol Horn",
            "Scalela Horn",
            "Scaleti Horn",
            "Scaledo Horn High",
            "Jazz Horn 1",
            "Jazz Horn 2",
            "Jazz Horn 3",
            "Jazzloop Horn",
            "Starspangban Horn 1",
            "Starspangban Horn 2",
            "Starspangban Horn 3",
            "Starspangban Horn 4",
            "Classicalloop Horn 1",
            "Classical Horn 8",
            "Classicalloop Horn 2"
        ]
    },
    {
        "name": "Lights",
        "options": [
            {
                "name": "Neon",
                "options": [
                    {
                        "name": "Color",
                        "type": "neon_rgb"
                    },
                    {
                        "name": "Layout",
                        "type": "neon_layout"
                    }
                ]
            },
            {
                "name": "Xenon",
                "type": "extended_labels",
                "target": "XenonLights",
                "labels": [
                    {
                        "name": "Stock Lights",
                        "value": false
                    },
                    {
                        "name": "Xenon Lights",
                        "value": true
                    }
                ]
            }
        ]
    },
    {
        "name": "Livery",
        "type": "livery",
        "mod": 48
    },
    {
        "name": "Plate",
        "type": "extended_labels",
        "labels": [
            {
                "name": "Blue on White 1",
                "value": 0
            },
            {
                "name": "Blue on White 2",
                "value": 3
            },
            {
                "name": "Blue on White 3",
                "value": 4
            },
            {
                "name": "Yellow on Blue",
                "value": 2
            },
            {
                "name": "Yellow on Black",
                "value": 1
            }
        ]
    },
    {
        "name": "Respray",
        "options": [
            {
                "name": "Primary Color",
                "type": "extended_labels",
                "labels": []
            },
            {
                "name": "Secondary Color",
                "type": "extended_labels",
                "labels": []
            },
            {
                "name": "Pearlescent",
                "type": "extended_labels",
                "labels": []
            }
        ]
    },
    {
        "name": "Roll Cage",
        "type": "normal",
        "mod": 5,
        "start_cost": 5000
    },
    {
        "name": "Roof",
        "type": "normal",
        "mod": 10,
        "start_cost": 1500
    },
    {
        "name": "Spoiler",
        "type": "normal",
        "mod": 0,
        "start_cost": 1000
    },
    {
        "name": "Skirts",
        "type": "normal",
        "mod": 3,
        "start_cost": 500
    },
    {
        "name": "Suspension",
        "type": "normal",
        "mod": 15,
        "start_cost": 5000,
        "increment": 5000,
        "labels": [
            "Lowered Suspension",
            "Street Suspension",
            "Sport Suspension",
            "Competition Suspension",
            "Race Suspension"
        ]
    },
    {
        "name": "Transmission",
        "type": "normal",
        "mod": 13,
        "start_cost": 7000,
        "increment": 3000,
        "labels": [
            "Street Transmission",
            "Sports Transmission",
            "Race Transmission"
        ]
    },
    {
        "name": "Turbo",
        "type": "extended_labels",
        "start_cost": 50000,
        "labels": [
            {
                "name": "None",
                "value": false
            },
            {
                "name": "Turbo Tuning",
                "value": true
            }
        ]
    },
    {
        "name": "Wheels",
        "options": [
            {
                "name": "Rims",
                "options": [
                    {
                        "name": "Highend",
                        "type": "wheels",
                        "wheel_type": 7,
                        "labels": []
                    },
                    {
                        "name": "Lowrider",
                        "type": "extended_labels",
                        "wheel_type": 2,
                        "labels": []
                    },
                    {
                        "name": "Muscle",
                        "type": "extended_labels",
                        "wheel_type": 1,
                        "labels": []
                    },
                    {
                        "name": "Offroad",
                        "type": "extended_labels",
                        "wheel_type": 4,
                        "labels": []
                    },
                    {
                        "name": "Sport",
                        "type": "extended_labels",
                        "wheel_type": 0,
                        "labels": []
                    },
                    {
                        "name": "SUV",
                        "type": "extended_labels",
                        "wheel_type": 3,
                        "labels":  []
                    },
                    {
                        "name": "Tuner",
                        "type": "extended_labels",
                        "wheel_type": 5,
                        "labels": []
                    }
                ]
            },
            {
                "name": "Tyre Smoke",
                "type": "extended_labels",
                "target": "TyreSmokeColor",
                "labels": [
                    {
                        "name": "White Tire Smoke",
                        "value": [ 255, 255, 255 ]
                    },
                    {
                        "name": "Black Tire Smoke",
                        "value": [ 1, 1, 1 ]
                    },
                    {
                        "name": "Blue Tire Smoke",
                        "value": [ 0, 150, 255 ]
                    },
                    {
                        "name": "Yellow Tire Smoke",
                        "value": [ 255, 255, 50 ]
                    },
                    {
                        "name": "Orange Tire Smoke",
                        "value": [ 255, 153, 51 ]
                    },
                    {
                        "name": "Red Tire Smoke",
                        "value": [ 255, 10, 10 ]
                    },
                    {
                        "name": "Green Tire Smoke",
                        "value": [ 10, 255, 10 ]
                    },
                    {
                        "name": "Purple Tire Smoke",
                        "value": [ 153, 10, 153 ]
                    },
                    {
                        "name": "Pink Tire Smoke",
                        "value": [ 255, 102, 178 ]
                    },
                    {
                        "name": "Gray Tire Smoke",
                        "value": [ 128, 128, 128 ]
                    }
                ]
            },
            {
                "name": "Wheel Details",
                "options": [
                    {
                        "name": "Bullet Proofing",
                        "target": "TyerBulletProof",
                        "type": "extended_labels",
                        "labels": [
                            {
                                "name": "Normal Tires",
                                "vale": false
                            },
                            {
                                "name": "Reinforced Tires",
                                "value": true
                            }
                        ]
                    },
                    {
                        "name": "Custom Wheels",
                        "target": "Variation",
                        "type": "extended_labels",
                        "labels": [
                            {
                                "name": "Stock Tires",
                                "value": false
                            },
                            {
                                "name": "Custom Tires",
                                "value": true
                            }
                        ]
                    },
                    {
                        "name": "Wheel Color",
                        "type": "extended_labels",
                        "labels": [

                        ]
                    }
                ]
            }
        ]
    },
    {
        "name": "Windows",
        "type": "extended_labels",
        "labels": [
            {
                "name": "Clear",
                "value": 0
            },
            {
                "name": "Lightsmoke",
                "value": 3
            },
            {
                "name": "Darksmoke",
                "value": 2
            },
            {
                "name": "Pure Black",
                "value": 1
            },
            {
                "name": "Limo",
                "value": 4
            },
            {
                "name": "Green",
                "value": 5
            }
        ]
    }
]

not thinking about the content of the file, but i know the filename has issues with -, uppercases and _

The resource name was “yimMenu” and the file trying to load was “data/lscustom/mods.json”.

Thanks for your time and answers, I’ve currently given up on loading resource files from subdirectories.

I’ll try again at a later date and share my insights in this thread.

1 Like

What else was in the resource at this time? There used to be something long ago where a directory name couldn’t match the base name of an asset file or such.

What exactly do you mean with, “What else was in the resource at this time?”.

I can send you a screenshot of how my structure is that I aim to get.
I’m trying to load the “data/lscustom/mods.json” file from the “logic/ls_custom/logic.lua” file. As far as I understand loading resource files is relative from the root of the resource directory and not from the script/lua file trying to load it?
Screenshot_1

And here a cleaner screenshot:
Screenshot_2

As you can see I have my json files all in the root but this could become hectic with a lot of files and I would like to store these in a sub directory.

Correct, I’m just suspecting you hit a packing bug :confused:

Can you cause the same issue with a repro resource with all scripts (except for a dummy load file and a script that calls LoadResourceFile) replaced with empty files but keeping the same directory structure and manifest? If so, please send such :smiley:

So while trying to recreate the bug I failed to recreate it, I then went to my project and rewrote the paths to the files and properly refreshed and restarted the resource and this time it worked.

I’m sorry to all whose time I wasted with this question, it’s just that I failed to accomplish this task twice before and was wondering if I’m still in the wrong or that’s it’s a problem with CFX.

Anyways, thanks for you guys answers and sorry again for my stupidity.

Edit:
Also what is that packing bug you were talking about, is it something that I may need to be aware of in the future?