I’m having difficulty transforming a JSON file into an HTML table using the RapidAPI API. Despite my attempts, I receive no output and no errors in my code. Could there be an oversight in my approach? I would greatly appreciate any assistance! Here’s a snippet of my code:
$.getJSON(settings).done(function(data){
console.log(data);
});
This logs output to the console, but I’m not able to render anything else. I’ve been struggling with this issue for two days now without success.
Hey FlyingLeaf, here's a quick way to convert JSON data into an HTML table using jQuery:
$.getJSON(settings).done(function(data) {
let table = '';
// Add headers
Object.keys(data[0]).forEach(key => {
table += ``;
});
table += '';
// Add data rows
data.forEach(item => {
table += '';
Object.values(item).forEach(value => {
table += ``;
});
table += '';
});
table += '';
$('#output').html(table); // Make sure there's a div with id="output"
});
Just ensure there's a div with id output
in your HTML where the table should appear. Cheers!