0

I have a app where i would like it to import all my jsonc files and be able to iterate through the objects i the files.

Right now i have this function, which imports the files:

   function importAll(r) {
        let files = {};
        r.keys().map(item => { files[item.replace('./', '')] = r(item); });
        return files;
    }

    const files = (importAll(require.context('./Service-Requests/', true, /\.jsonc$/)));

It works, but when i then iterate over the objects i the jsonc files, i can not find the properties.

If i do a console.log the files i gives me this: enter image description here

but if it is normal json files, i get the objects: enter image description here

so how do I use the jsonc files so i can access the properties from each object??

i use this to loop through the files:

Object.keys(files).forEach(key => {
            if (files[key].title === e.target.value) {
                setData(files[key])
                setInput(files[key].Input)
            }
        });
robertklep
  • 198,204
  • 35
  • 394
  • 381
Nadia Hansen
  • 697
  • 2
  • 6
  • 16

0 Answers0