0

I want to populate these json file to html and i have tried no avail, i'm hoping someone could put me on the right track.

I tried to fetch this json using the code i tried json link json File

Added: i have tried https://developer.mozilla.org/en-US/docs/Web/API/Response/json but didn't give result as my json array went up almost 4 level

Here is the code i tried

    fetch("./data.json") 
  .then(function (result) {
    appendData(result);
  })
  .catch(error => console.log('error', error));

  function appendData(result) {
            var mainContainer = document.getElementById("myData");
            for (var i = 0; i < result.length; i++) {
               
                console.log(data.salaryPaymentDetails.result[i].amount)
            }
        }

It give me undefine, don't know what am missing

Marshall Unduemi
  • 207
  • 2
  • 13
  • You need to use the [`Response.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json) API – Terry Jan 03 '23 at 12:16
  • The parsed JSON will give you an object. It sounds like you want to iterate over `result.data[0].salaryPaymentDetails` rather than `result` if you want the amount values. – Andy Jan 03 '23 at 12:19

0 Answers0