I would like to add names to multiple JSON objects at the same time.
I tried this:
let jdata = fs.readFileSync('participants.json');
let json = JSON.parse(jdata);
jury = ["jury1", "jury2"];
for(i=1; i<3; i++){
data = json.jury[i];
console.log(data);
}
My JSON file: { "jury1": [ "name1", "name2", "name3" ], "jury2": [ "name1", "name2", "name3" ] } This gives me an error:
data = json.jurys[i];
^
TypeError: Cannot read property '1' of undefined
I haven't used JSON before and i'm not sure how to get all of the values from these objects. Could someone tell me what i'm doing wrong? Thanks for your time and help already!
data = json[jury[i]];