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:
but if it is normal json files, i get the objects:
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)
}
});