I am using JSON to store and retrieve some values from json file. I am trying to fetch the JSON data using javascript. The JSON data has array in array list. I am able to fetch the object list but unable to fetch inner array. Below is my JSON Data and it's format. What am I missing?
artifacts.json
{
"artifacts": [
{
"technology": "Agile Software Development",
"techBasedArtifacts": [
{
"title": "Agile 1",
"artifactLink": "https://www.google.com/"
},
{
"title": "Agile 2",
"artifactLink": "https://www.google.com/"
}
]
},
{
"technology": "UI Development",
"techBasedArtifacts": [
{
"title": "UI 1",
"artifactLink": "https://www.google.com/"
},
{
"title": "UI 2",
"artifactLink": "https://www.google.com/"
}
]
}
]
}
app.js
"use-strict";
let requestURL = "./artifacts.json";
let request = new XMLHttpRequest();
request.open('GET', requestURL);
request.responseType = 'text';
request.send();
request.onload = () => {
const a = request.response;
const b = JSON.parse(a);
console.log(b.artifacts) //Shows object array which is good
console.log(b.artifacts.techBasedArtifacts) // Shows undefined
}
artifactsarray and for each object grab thetechBasedArtifactsarray. Then you'd probably need to iterate over that array too depending on the information you need.