I have a json file which contains json objects like following .
{
"RegionNames" : ["Region1", "Region2"],
"StageNames" : ["Stage1", "Stage2"],
"stages" : {
"Stage1" : {
"Region1" : {
"var1": "value1",
"var2": "value2"
},
"Region2" : {
"var1": "value1",
"var2": "value2"
}
},
"Stage2" : {
"Region2" : {
"var1": "value1";,
"var2": "value2";
}
}
}
}
I want to access this variable the var1 & var2 of both Region1 & Region2 in each stage .
//How i've tried accessing them in another typeScript file , the above content is in jsonContent.json : -
const stages =jsonContent.StageNames;
const regions = jsonContent.RegionNames;
for (let stageIndex in stages) {
for (let regionIndex in regions) {
console.log("Variable1 value :"+ jsonContent.stages[stageIndex].regions[regionIndex].var1)
console.log("Variable2 value :"+
jsonContent.stages[stageIndex].regions[regionIndex].var2)
}
}
Can someone please help me in this accessing in json using loop .
I need to use "RegionNames" & "StageNames" variables to run that loop , but not able to do so . Can someone please help .
let var = {means that it's not JSON. It also has syntax errors.