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

402
Views
Generate html table from json url with data from key, value also from parent without key

Im generating an html table with data from json url. I want to include parent value without key to these data.

Json structure:

{
    "gzpik1gqlnm":
        {"owner_name":"user02","room_name":"131","country":"EN","max":2,"current":1,"password":0},
            "d1vn67n7sgu":
                {"owner_name":"user09","room_name":"254","country":"EN","max":2,"current":1,"password":0}
}

Javascript:

    setInterval(function(){
  $.getJSON("somejson.url", function(data){
    var room_data = '';
    $("#roomtabletbody").empty();
   
     $.each(data, function(key, value){       
      room_data += '<tr valign="top">';
      room_data += '<td>'+value.country+'</td>';      
      room_data += '<td>'+value.owner_name+'</td>';
      room_data += '<td>'+value.room_name+'</td>';
      room_data += '<td>'+value.current+'/'+value.max+'</td>';
      room_data += '<td>'+value.password+'</td>';
      room_data += '<td><a class="join" href="">Join</a></td>';
      room_data += '<tr>';

    });
    $('#roomtabletbody').append(room_data);
    
  });

        
    }, 1000);

generated table:

country owner_name  room_name   current/max password
  EN     user02         131          1/2       0
  EN     user09         254          1/2       0

table im trying to get at:

parent      country owner_name  room_name   current/max password
gzpik1gqlnm    EN    user02         131          1/2       0
d1vn67n7sgu    EN    user09         254          1/2       0

Whats the right direction?

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

0

Before room_data += '<td>'+value.country+'</td>';, add : room_data += '<td>'+key+'</td>';

And success. If you feel this is the right answer don't forget to mark this as correct answer.

    setInterval(function(){
  $.getJSON("somejson.url", function(data){
    var room_data = '';
    $("#roomtabletbody").empty();
   
     $.each(data, function(key, value){       
      room_data += '<tr valign="top">';
      room_data += '<td>'+key+'</td>';
      room_data += '<td>'+value.country+'</td>';      
      room_data += '<td>'+value.owner_name+'</td>';
      room_data += '<td>'+value.room_name+'</td>';
      room_data += '<td>'+value.current+'/'+value.max+'</td>';
      room_data += '<td>'+value.password+'</td>';
      room_data += '<td><a class="join" href="">Join</a></td>';
      room_data += '<tr>';

    });
    $('#roomtabletbody').append(room_data);
    
  });

        
    }, 1000);

Don't forget to add new header in <thead>.

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!