I made a JSON file with multiple objects containing named values assigned to strings like this,
{
"Obj1" : {
"Val1": "Obj 1, Test Value 1",
"Val2": "Obj 1, Test Value 2",
"Val3": "Obj 1, Test Value 3"
},
"Obj2" : {
"Val1": "Obj 2, Test Value 1",
"Val2": "Obj 2, Test Value 2",
"Val3": "Obj 2, Test Value 3"
}
}
I needed to access each value in each object individually in Next JS, I tried to import and parse the data,
import data from '~/data.json';
const obj1: any = JSON.parse(data["Obj1"]); // Side Note: What type should this const be?
console.log(obj1.Val1); // Desired Output: " Obj1, Test Value 1 "
Although, when I attempted this I ran into this error, " Argument of type '{ Val1: string; }' is not assignable to parameter of type 'string'.ts(2345) "
I cannot find how to get around this error no matter what I do. Is my JSON or TS incorrect?