I am trying to read a JSON file and set a value based on what is read.
Here is what my leaves.json looks like:
{
"Button_1": {
"text": "Github",
"link": "https://github.com/"
},
"Button_2": {
"text": "LinkedIn",
"link": "https://www.linkedin.com/"
}
}
Here is the JSON reading code:
var buttons_json = fetch('./leaves.json')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.log(error));
I am unable to pull a value from the JSON object in memory, it tells me the value is undefined. For example:
console.log(buttons_json["Button_1"]["text"]);
Is undefined. You can see the console output here giving us undefined, but the JSON Object is properly read. Any ideas?