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

135
Views
Get and print informations from Json File in HTML website

I need to create a basic website where I have to print informations from a Json file. With Javascript.

What I would like to have it's, the picture of the results

But I have no idea how to do that cause I'm a beginner in Javascript. Can you help me please ? Thanks a lot Theo

{
    "number_of_results": 20,
    "results": [
        {
            "name": {
                "first": "Test",
                "last": "Test"
            },
            "date_of_birth": {
                "date": "1985-12-03T02:05:33",
                "age": 36
            },
            "picture": {
                "large": "apple.png",
            },
        },
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It appears that your data structure doesn't quite match what you had in your script so some of the corrections here (from your version) are:

  • change .firstName to .name.first
  • reference results array so results.name becomes results[i].name
  • email shows undefined but that's because it is not in the data (at least not in your example)
  • the image tag shows up with the right source, but because those are not full urls, the image will likely appear broken until the data is more realistic.

The following script should append both the div with the name/email and the image.

function appendData(data) {
    var mainContainer = document.getElementById("myData");
    for (var i = 0; i < data.results.length; i++) {
        var div = document.createElement("div");
        div.innerHTML = 'Email: ' + data.results[i].email + ' First Name :' + data.results[i].name.first;
        mainContainer.appendChild(div);
        var img = document.createElement("img");
        img.src = data.results[i].picture.large;
        mainContainer.appendChild(img);
    }
}
about 4 years ago · Juan Pablo Isaza Report

0

Try This:

function appendData(data) {
    var mainContainer = document.getElementById("myData");
    for (var i = 0; i < data.results.length; i++) {
        var div = document.createElement("div"); 
        div.innerHTML = 'Email: ' + (data.results[i].email?data.results[i].email:'') + ' First Name :' + (data.results[i].name?data.results[i].name.first:'');
        mainContainer.appendChild(div);
    }
}
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!