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

216
Views
Get Json data from another folder

I am still new to using JSON files . is there a way to get use data from my json file in a js file that will be called by a button click in another html file. the function is in the script.js

----------
  \
   ----> assets
   |       \
   |        ----> Data
   |                 \
   |                  ---->Data.JSON
   \
    ----> js
   |    \
   |     ----> script.js
   |
   \
    ---->Files
           \
            ---->page.html



function Replace(Data)
{
    const obj = JSON.parse(Data);
    
    var length = Object.keys(obj.employees).length;
    console.log(length);

    document.getElementById('test').innerHTML = "";
    for(let i = 0; i < length; i++) 
    {
        document.getElementById('test').innerHTML += "<br>"+obj.employees[i].firstName + " " + obj.employees[i].lastName ;
        console.log(obj.employees[i].firstName + " " + obj.employees[i].lastName);
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Could you do something like this?

/*
Example Data:
{
    employees: [
        {
            firstName: "John",
            lastName: "Doe",
        }
    ]
}
*/
const data = require("./assets/Data/Data.json");

function appendData() {
  data.employees.forEach((employee) => {
    document.getElementById(
      "test"
    ).innerHTML += `<br>${employee.firstName} ${employee.lastName}`;
  });
}

appendData()
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!