Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
Fetching a local JSON file not working having Promise issues

Hi I am trying to fetch a local JSON file I used localhost for this but the problem I am having is when I fetch it using:

const endpoint = "http://127.0.0.1:5500/appendixA.json"

const fetchedItems = fetch(endpoint)
    .then(res => res.json())
    .then(result => result.appendix_a)
    .catch(e => console.log("error: ", e))

or using async await

const fetchFunc = async () => {
     let response = await fetch(endpoint);
     let jsonResponse = await response.json()
     return jsonResponse.appendix_a;
}

So when I console.log either of them console.log(fetchedItems) console.log(fetchFunc()) I am not getting result as a variable array ie [ //results ] But instead I am getting just a [Promise]

Here is a sample off the JSON file

    {
        "appendix_a": [
            {
                "id": 1,
                "stakeholder": "Commercial Director",
                "user_story": "As a user I need to be able to insert my name into the form"
            },
            {
                "id": 2,
                "stakeholder": "Commercial Director",
                "user_story": "As a user I need to be able to insert my email into the form"
            }
        ]
    }

Why is this happening as I have done res.json() on the initial .then call as well as I have done await res.json() inside the async function

Please clarify for me that.

As I plan to insert the fetch data into a ul element like this which obviously wont work because of the Promise

const ul = document.querySelector('ul');
let li = document.createElement('li');

fetchedItems.map(pa => {
        li.innerHTML = `
<span>${pa.id}</span> 
<p>${pa.stakeholder}></p> 
<p>${pa.user_story}</p> `
        return ul.appendChild(li);            
});

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're in async world now, so you have to work with callbacks. This:

console.log(fetchedItems)

Becomes:

fetchedItems.then(console.log);

And:

console.log(fetchFunc());

Would be:

fetchFunc().then(console.log);

Or:

console.log(await fetchFunc());
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!